Shortly, in C language all char arrays are signing to random values after running.
So, when you're trying to print it, it will print all those random values too. You can't check it for NULL, because it's feature of C language.
Example -
http://stackoverflow.com/questions/12676804/printing-char-arrays-in-cIt seems like you have to end array with value '\0' manually after each writing to array.
I mean to use something like
Quote
...
printf("Enter a name: ");
scanf("%s", names[i]);
if (i!=5)
names[i+1][0]='\0';
...
in both if statements (at the end and in loop)
It will add \0 char to first place of next row after each entering of name.
+ you have to add new if statement inside loop within inside menu_op == 2.
Quote
...
if (menu_op == 2) {
int j = 0;
printf("\nNames that have been entered:");
for (; j < 5; j++)
if (names[j][0] != '\0')
printf("\n\t%s", names[j]);
else break;
...
it will simply stop printing names after finding this \0 char in line.
btw, \0 is equal of NULL, but for char and strings. down
By whatever reason, in C language CPU gives random values after allocating memory for char and string valuebles.
This post was edited by dimon222 on Mar 16 2013 01:51pm