Question:
c programming text files helps T.T?
Siaw
2011-10-17 04:49:53 UTC
Argh...I am totally lost...I newly learn how to edit text files by c programming but now I encounter some basic question but I don't know how to do....so please help ~ Below is the question.

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
Three answers:
Freagra Kotae
2011-10-17 05:00:32 UTC
Maybe you're missing ')' in this line below? There are 3 of '(' , but there are only 2 of ')' so...



while ((fgets(ch, 80, fp) != NULL)
Silent
2011-10-17 04:57:14 UTC
Well, take a look at the line identified in the error message:



while ((fgets(ch, 80, fp) != NULL)



Just like the error message says, you're missing a ) in this line. You have three open parentheses but only 2 close parentheses.
mincey
2016-10-03 01:12:18 UTC
Write a maximum mandatory application that performs the subsequent steps: on the spot the guy to bypass right into a string, and allow them to style it in. this may be an finished sentence, with the newline indicating the right of the string. you're able to anticipate the string must be no greater suitable than one hundred characters, so declare your array hence. demonstrate the subsequent menu: A) count style the quantity of vowels in the string B) count style the quantity of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) demonstrate the present string F) enter a distinctive string M) demonstrate this menu X) go out the applying enter a loop, allowing the guy to style in a menu determination each and every time. Loop will ought to shield till the guy enters the command to bypass out. larger and lowercase letters will must be allowed for the menu alternatives. while the A or B training are entered (counting vowels or consonants), call the corresponding place, then print the outcomes while the C or D training are chosen, purely call the right place to rework the string. Do no longer do any output from maximum mandatory on those training. while E is chosen, print the contents of the saved string. while F is chosen, enable a clean string to be typed -- this might replace the past one. The menu will ought to maximum functional be displayed as quickly as on the start up, or maybe although each and every time the M option is chosen


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...