Explain a file operation in C with an example.



Explain a file operation in C with an example...

Answer / Shalini Gupta

"A common file operation in C is reading a file. Here's an example using the 'fopen', 'fread', and 'fclose' functions:n- Open the file: `FILE *fp = fopen("example.txt", "r")`n- Read data from the file: `int ch; while((ch = fgetc(fp)) != EOF) printf("%c", ch);`n- Close the file: `fclose(fp);`

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

enum colors {BLACK,BLUE,GREEN} main() { printf("%d..%d..%d",BLACK,BLUE,GREEN); return(1); }

4 Answers   ME,


What is the use of typedef in structure in c?

1 Answers  


What will be the result of the following program? main() { char p[]="String"; int x=0; if(p=="String") { printf("Pass 1"); if(p[sizeof(p)-2]=='g') printf("Pass 2"); else printf("Fail 2"); } else { printf("Fail 1"); if(p[sizeof(p)-2]=='g') printf("Pass 2"); else printf("Fail 2"); } } a) Pass 1, Pass 2 b) Fail 1, Fail 2 c) Pass 1, Fail 2 d) Fail 1, Pass 2 e) syntax error during compilation

10 Answers   IBM,


What is wrong with this statement? Myname = 'robin';

1 Answers  


Explain how do you search data in a data file using random access method?

1 Answers  


In c programming language, how many parameters can be passed to a function ?

1 Answers  


What is meant by operator precedence?

1 Answers  


This is a variation of the call_me function in the previous question:call_me (myvar)int *myvar;{ *myvar += 5; }The correct way to call this function from main() will be a) call_me(myvar) b) call_me(*myvar) c) call_me(&myvar) d) expanded memory

1 Answers  


Explain pointer. What are function pointers in C?

1 Answers   HCL,


how to generate the length of a string without using len funtion?

4 Answers  


Describe the header file and its usage in c programming?

1 Answers  


Explain what is output redirection?

1 Answers  


Categories