C Programming - Library Functions - Discussion

4. 

Data written into a file using fwrite() can be read back using fscanf()

[A]. True
[B]. False

Answer: Option B

Explanation:

fwrite() - Unformatted write in to a file.
fscanf() - Formatted read from a file.


Vak said: (Jul 8, 2011)  
This question is ambiguous, if you write a string "10 10 10" with fwrite you can read with "%d %d %d".

Divya Samunuru said: (Jul 26, 2011)  
Please give me detailed explanation.

Piyush S Patel said: (Jul 29, 2011)  
@DS.

Check out the prototype and retyrn function in the help index. The explantion is quite awesome.

Bobby said: (Aug 12, 2011)  
@Divya. We can only call the functions after we defined.

Neha said: (May 23, 2012)  
I think its not possible because fwrite writes the data in binary form and fscanf reads text data.

Naseeb said: (Feb 10, 2014)  
What is text and binary data?

Samreen said: (Mar 28, 2014)  
Can somebody explain me in detail?

Neelaveni said: (Sep 15, 2014)  
fwrite writes data into the file in binary format.

fread is used to read the data i.e written by fwrite.

Polina said: (May 14, 2015)  
#include<stdio.h>

int main()
{
char str [80];
char buffer[] = { 'a' , 'y' , 'z' };
FILE *pFile;

pFile=fopen("example.txt", "rw");
fwrite (buffer , sizeof(char), sizeof(buffer), pFile);
fflush(pFile);
fseek(pFile, 0, SEEK_SET);
fscanf (pFile, "%s", str);
printf ("I have read: %s \n",str);
fclose (pFile);

return 0;
}

Vishalakshi said: (Dec 2, 2016)  
@ Naseeb :

text:text files are human readable form & they can be created and read using any text editor but binary files are not in human readable form and they can be created and read for only by specific programs written for them.

Thank you, have a nice day.

Liyo said: (Feb 26, 2017)  
fwrite() stresses Unformatted, but fscanf() stresses formatted.

Jon said: (Mar 16, 2017)  
You can write a file using fwrite that is appropriate for reading using fscanf.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.