08_Files_7113d00e6ea5d7136ca7029de837dbe0
08_Files_7113d00e6ea5d7136ca7029de837dbe0
Files
• Files….
FILE *filePointer;
FILE *filePointer;
filePointer = fopen(“fileName.txt”, “mode”);
• r – read mode
• Searches for the file, if the file exists then fopen( ) loads it into memory and sets up a
pointer which points to the first character in it
• If the file cannot be opened or file does not exist, then fopen( ) returns NULL
• w – write mode
• Searches for the file, if the file exists, then its contents are overwritten
• If the file doesn’t exist, a new file is created
• Returns NULL, if unable to open file
• a – append mode
• Searches for the file, if the file is opened successfully fopen() loads it into memory and
sets up a pointer that points to the last character in it
• If the file doesn’t exist, a new file is created and fopen() loads it into memory and sets
up a pointer which points to the first position in it
• Returns NULL, if unable to open file
• The functions fgets() reads up to n-1 characters from the input stream
referenced by fp. It copies the read string into the buffer buf, appending
a null character to terminate the string
• fscanf() function read strings from a file, but it stops reading after
encountering the first space character
Output
1 : This
2 : is testing for fprintf...
Output
1 : This is