Instead of
UseCode:scanf("%s",&list[i].name);
In the future, remember an array name is the address of the array; so no need most of the time to put an address operator (&) in front of it.Code:scanf("%s",list[i].name);
Tim S.
Printable View
Instead of
UseCode:scanf("%s",&list[i].name);
In the future, remember an array name is the address of the array; so no need most of the time to put an address operator (&) in front of it.Code:scanf("%s",list[i].name);
Tim S.
If you declare a variable like
the compiler just allocates enough memory to store a value of this type, but it doesn't clear the memory. So whatever value is stored at this memory location is still there (probably just garbage).Code:int x;
initializes the variable x to 0 and then you can be sure that this value stays there as long as you don't change it.Code:int x = 0;
The problem in your code is that
compares the pointer "list[i].name" to the pointer "NULL" and the result is always true because all elements of list have a valid memory address and thus they are unequal to NULL. What you want is to compare the value the pointer "list[i].name" points to to a value which denotes an empty string (usually '\0' as the only character in the string). But you have to initialize your list-array to be able to do this.Code:if(list[i].name != NULL)
I also suggest reading a tutorial about pointers, arrays and strings.
Bye, Andreas