Erin's CS stuff

CS stuff!

File IO Quick Guide

Type Application Example Notes
FILE*'s
fopen
fclose
before you can interact with a file, you need to create a connection or stream
  1. save the connection
    • declare a FILE pointer
  2. open the file
    • call the fopen function
      • send in the filename string
      • send in the mode string (double quotes, not single!)
        • "r" is read
        • "w" is write
        • "a" is append
  3. verify the connection is made
    • check the FILE pointer for the NULL pointer
      • if it's the NULL pointer, quit
      • CAUTION! If the FILE pointer is NULL, you will get a segmentation fault if you use it.
  4. close the connection (after interacting with the file)
    • call the fclose function
      • send in the FILE pointer
fprintf outputs text to a stream
  • this looks just like Formatted IO, but with the FILE pointer as the first argument
  • you can use still things like field width and precision to format how your output looks
fscanf gets input text from a stream
  • this looks just like Formatted IO, but with the FILE pointer as the first argument
fgets gets input text as a C-Style String from a stream
  • this looks just like Formatted IO with C-Style Strings, but with the FILE pointer as the last argument