C Programming - Library Functions - Discussion
Discussion Forum : Library Functions - True / False Questions (Q.No. 4)
4.
Data written into a file using fwrite() can be read back using fscanf()
Answer: Option
Explanation:
fwrite() - Unformatted write in to a file.
fscanf() - Formatted read from a file.
Discussion:
12 comments Page 1 of 2.
Polina said:
1 decade ago
#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;
}
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;
}
(1)
Vishalakshi said:
9 years ago
@ 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.
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.
Vak said:
1 decade ago
This question is ambiguous, if you write a string "10 10 10" with fwrite you can read with "%d %d %d".
Neelaveni said:
1 decade ago
fwrite writes data into the file in binary format.
fread is used to read the data i.e written by fwrite.
fread is used to read the data i.e written by fwrite.
Piyush s patel said:
1 decade ago
@DS.
Check out the prototype and retyrn function in the help index. The explantion is quite awesome.
Check out the prototype and retyrn function in the help index. The explantion is quite awesome.
Neha said:
1 decade ago
I think its not possible because fwrite writes the data in binary form and fscanf reads text data.
(1)
Jon said:
8 years ago
You can write a file using fwrite that is appropriate for reading using fscanf.
Liyo said:
8 years ago
fwrite() stresses Unformatted, but fscanf() stresses formatted.
Bobby said:
1 decade ago
@Divya. We can only call the functions after we defined.
Divya samunuru said:
1 decade ago
Please give me detailed explanation.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers