Week 11 Lecture.docx - Week 11 Lecture Quiz on text files to more input and output 50 50 A file is a named area of secondary storage EOF typically has a

Week 11 Lecture.docx - Week 11 Lecture Quiz on text files...

This preview shows page 1 out of 1 page.

Week 11 Lecture Quiz on text files to more input and output. 50% 50% A file is a named area of secondary storage EOF typically has a value of -1. All input, output functions read a character from a stream and return it as an int File name needs to have .txt extension Getch() reads one by one. When reaches end of file, will get an indicator called EOF. When done reading all the data from the file, will return a value to the function that is -1. Fgetc() returns integer type; so to differentiate from EOF, EOF returns -1. FILE *fp = NULL; key word FILE is the object of the FILE structure. Connects to where the file is staying in secondary storage. So here, making a pointer to the file and initialize it with NULL so that it IS NOT POINTING TO ANY GARBAGE ADDRESS. Pointer is
Image of page 1

You've reached the end of your free preview.

Want to read the whole page?

Unformatted text preview: a variable so make sure to initialize it so that it does not hold a garbage value. NULL value is a constant 0. Now, need to give pointer the address of a variable. Fopen opens the named file and returns the address FILE*fopen(const char file_name, const char mode); Fopen returns NULL if it fails to connect to the file Pt = fopen(“filename.txt”, “mode”); gives address of the file to the pointer a=write to the end of the file to open a file in write mode: fp = fopen(“alpha.txt”, “w”); never read end of file – we always read from end of file backwards. If want to read past end of file, use feof(fp)==0 go to end of file...
View Full Document

  • Fall '10
  • michaelhedenreich

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

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors