FileReadingAndWriting_1

FileReadingAndWriting_1 - Descriptions of a few functions...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Descriptions of a few functions for file manipulation. This is not exhaustive. There are other methods for reading and writing from and two a file. fgets In order to read from a file or write to a file, you must have a file pointer pointing to the file that you wish to read from or write too. Such pointers are of the FILE* datatype. Then you would use the fopen function to open a relevant file. The declaration would look like the line below. FILE* InputFile = fopen("name_of_file.ext", "w") The function fopen(char*, char*) has two arguments, one of them is a string with the name of your file, and the other one is a string delimiting the way you wish to open your file. "r" means read, "w" means overwrite, "a" means append to the end. "t" means open the file as a text file (This is the default if you put nothing but a "r" or a "w" it will open as a text file). "b" means open the file as a binary file. You can read input with fgets. fgets will read either an entire file, or a single line so long as the
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern