1 / 14

Group 6 fread , fwrite / fgets , fputs

Group 6 fread , fwrite / fgets , fputs. William Martinez Benjamin Allen Javier Morejon Derek Gutierrez Sebastian Gonzalez. What are they?. fwrite - The fwrite function is used to write data to a file fread - The fread function is used to read data from a file

mandell
Download Presentation

Group 6 fread , fwrite / fgets , fputs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Group 6fread, fwrite/ fgets, fputs William Martinez Benjamin Allen Javier Morejon Derek Gutierrez Sebastian Gonzalez

  2. What are they? • fwrite- The fwrite function is used to write data to a file • fread- The fread function is used to read data from a file • fgets-Reads characters from stream and stores them as a C string. • fputs-put the string on a stream. • ftell-Returns the current position of the file read/write pointer. • rewind- Takes the pointer into a file to the beginning of the stream.

  3. fread/fwrite Include libraries. Declare arrays. Declares int and FILE pointer. Establishes values of the elements of the array. Opens the FILE and retrieves the data and places it into another array. Opens the FILE and writes the contents of the array into the file. Displays both arrays in order to show that they are both the same.

  4. fgets/fputs Include necessary libraries. Define the length of the character reading buffer. Initializes the character array. Reads the first 5 characters from the FILE and gives the position indicator. Creates a file and writes the entire contents of the array into the FILE. Reads the first 5 characters again and gives the position indicator again, demonstrating that the stream was rewound. Reads the next 5 characters from the FILE and gives the position indicator. Relocates the position indicator to the beginning of the FILE.

  5. Alternate Examples Two screen captures of alternate examples, showing the use of fread/fwrite and fputs/fgets, respectively.

  6. You can read or write data to a file as a whole or piece by piece, depending on which function you use. The position indicator never moves on its own. It must be moved by reading characters or a separate command (stays where it was after the last statement in which it was used). Using these four functions requires a knowledge of the functions fopen and fclose. Lessons Learned

More Related