read file in c

0 Delphin Sidieu · March 29, 2015
Hi,i'm a beginner in c i have a question about the read file in c(fopen function),why do we use the read file for? i hope u understand my english.Thanks

Post a Reply


Oldest  Newest  Rating
+1 0x13a _ · April 8, 2015
Working with files in C is very simple

This is a basic example

int main()
char ch, file_name[25];
FILE *fp;
printf("Enter the name of file you wish to see\n");
fp = fopen(file_name,"r"); // read mode
if( fp == NULL )
perror("Error while opening the file.\n");
printf("The contents of %s file are :\n", file_name);
while( ( ch = fgetc(fp) ) != EOF )
return 0;
0 Dol Lod · March 29, 2015
Fopen is used to open the file so it could be read in binary if necessary. If you simply use an ordinary read it will not work for files in binary like images or video ex. .jpg or .avi. Fopen can work on both ordinary files and binary files.

Does that answer your question?
0 Yaron X · April 8, 2015
fopen() - opening a file. the file can be opened for reading, writing or both.
fread() - reading from a file (must be opened first through fopen )
fwrite() - writing to a file (must be opened first through fopen )
fclose()  - closing a file
0 Jim Fp · April 8, 2015
Use ifstream, search it
0 Delphin Sidieu · March 29, 2015
yes,but what's confusing me is,i wanna know if it's kind of data base or something. Like if i make a program to take users information like his/her age,adress,name,birthdate ect if i can save them with tis function.Thank you
0 Jim Fp · April 9, 2015
You make this really confusing... Check buckys tutorials. Its in the end where he explains how to work with files. Its easiest with ifstream we dont have to make it more difficult :)
  • 1



One of the most popular languages of all time.

Bucky Roberts Administrator