Originally posted by bluebob
fgets(&MemberData[counter1].membernumber,10,
without seeing more of your code, I'd guess the problem is here. What is MemberData[counter1].membernumber defined as? If it's a char array then you don't need the & in front of the name. THis is because fgets takes a char pointer as its first arg. The name of a char array (char buffer[10]) is all you need to pass.
Also, I believe the loop method in the below example is slightly better. You can always check the value of errno if the fgets call fails.
Example:
Code:
#include <stdio.h>
int main(void)
{
FILE *fp;
char buf[100];
if ((fp = fopen("junk6.c", "r")) == NULL)
{
perror("file");
return (1);
}
while (fgets(buf, sizeof(buf), fp))
printf("%s", buf);
return(0);
}
Lastly, the newline will be kept in the array, but this is in my documentation, so be warned:
A common programming error is to assume the presence of a new-line character in every string that is read into the array. A new-line character will not be present when more than n-1 characters occur before the new-line. Also, a new-line character might not appear as the last character in a file, just before end-of-file