Kem Kem - 15 days ago 9
C Question

Iterate through array in c manually

I have a string array of 10 words and I want to display them.

However, I want the user to press a key and the next values are displayed.

I.e, it should display a, then the user presses a key and it displays b.

How can I achieve this?

char destination[10][10]

for (i=0; i<10; i++){

printf(Enter a name: );
scanf( "%s", name[i])
}


for (i=0; i<10; i++){

printf(" Name %d: %s", i, name[i]);
getch();
}

Answer

I'm not sure what you want, nor what your actual problem is, but this works fine here:

#include <stdio.h>
#include <conio.h>

int main() {

    char name[10][10];
    int i;

    for (i = 0; i<10; i++) {

      printf("Enter a name : ");
      scanf("%s", name[i]);
    }

  for (i = 0; i<10; i++) {

    printf(" Name %d: %s", i, name[i]);
    getch();
  }    
}