ENGM 1081 Lecture Notes - Lecture 5: Data File
ENGM 1081 verified notes
5/29View all
Document Summary
Declaring files: file* fin; - for input files, file* fout; -for output files. A variable type file* (file pointer) which references the document which we either wish to read or write to is in the computer system. Thus, we could say that "fin" and "fout" are file pointer variables that give the program direction to the files we wish to interact with as part of our program. Opening an input file to be read fin = fopen("file_being_read. txt","r"); Opening an output file to write fout = fopen("file_being_written_to. txt","w"); Opening an output file to append fout = fopen("file_being_appended. txt","a"); Writing versus appending: when we write to a file, we generate a new file with the exact file name and extension identified in fopen() located in the directory where we have saved the program. If the file does not yet exist (for example, during the first time running the program) then a new file will be created as normal.