How do I place 2-3 digit numbers obtained from a file into an array? [closed]
main ()
{
FILE *pRead;
FILE *pWrite;
char lastname [20];
char firstname [20];
char grade [4];
char gradefi [4];
char gradeltr [3];
int i=0;
pRead=fopen ("testtext.dat", "r");
if (pRead == NULL || pWrite == NULL)
printf ("\nFile cannot be opened\n");
else
printf ("\nContents of testtext.dat\n\n");
fscanf (pRead, "%[^,]%[^\n]%s", lastname, firstname, &grade);
printf ("\n");
pWrite=fopen ("report.txt", "w");
fprintf (pWrite, "%s %s %s\n", firstname, lastname, &grade);
while (!feof(pRead))
{
++i;
printf ("%s %s %s\n", firstname, lastname, &grade);
fscanf(pRead, "%[^,]%[^\n]%s", lastname, firstname, &grade);
fprintf (pWrite, "%s %s %s\n", firstname, lastname, &grade);
}
fclose(pRead);
fclose(pWrite);
printf ("\nThere are %d student(s) in this list\n", i);
Well, not to look like an old stale paranoid fart or anything, but I suggest you put some curly brackets around the consequent statments after else
and see what happens.
精彩评论