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.
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.
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.