Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying file text/nuumbers/ect into a variable

Status
Not open for further replies.

tizz

Programmer
Aug 3, 2006
1
0
0
US
I understand how to open files, and now I want to try and copy the contents of a text file to a character array. I have read about fgets() and fread() and fgetc(), but I am not sure how to use these to copy the contents of the file. Any help is appreciated.
 
Code:
char buff[BUFSIZ];
FILE *fp = fopen("file.txt","r");
while ( fgets( buff, sizeof buff, fp ) != NULL ) {
  // do something with every successive line in the file
  // until the end of the file is reached.
}

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top