Siaw
2011-10-17 04:49:53 UTC
Write a program that reads the input from the text file, number.data, and then writes these data to a new file named "output.txt". Your program must apply array and structure in a text files.
_________________________________________________________________________________
Below is my coding so far...
#include
#include
#include
int main(void) {
FILE *fp;
char ch[80];
if((fp = fopen("number.dat","r")) == NULL)
printf("Cannot open file\n");
else {
while ((fgets(ch, 80, fp) != NULL)
printf("%s", ch);
fclose(fp);
}
return 0;
}
_______________________________________________________________________________
I want to read input from number.dat but it keep showing error C2146: syntax error : missing ')' before identifier 'printf'. What happen? And also how can I write the readed data into a new text files? Very thanks. Oh...also note that the number.dat have the following information.
1 Ng 4.4
2 Lee 4.5
3 Lau 6.6