1 / 16

Theo Jenetopulos William Murcia Melissa Sarduy Bruce Eckel

HELLO My Name is. Theo Jenetopulos William Murcia Melissa Sarduy Bruce Eckel. Freads / Fwrites. Freads / Fwrites. Block Diagram. Block Diagram. Example. / * fwrrd.c */    #include < stdio.h >    #include < math.h >    #define SIZE 20    void main ()

keita
Télécharger la présentation

Theo Jenetopulos William Murcia Melissa Sarduy Bruce Eckel

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. HELLO My Name is Theo Jenetopulos William Murcia Melissa Sarduy Bruce Eckel

  2. Freads/ Fwrites

  3. Freads/ Fwrites

  4. Block Diagram

  5. Block Diagram

  6. Example /* fwrrd.c */    #include <stdio.h>    #include <math.h>    #define SIZE 20    void main()    {int n;     float d[SIZE];     FILE *fp;      for( n = 0; n < SIZE; ++n )                 /* Fill array with roots. */     {       d[n] = (float)sqrt( (double)n );     }fp = fopen( "data", "w+" );                 /* Open file. */fwrite( d, sizeof( float ), SIZE, fp );    /* Write it to file. */     rewind( fp );                               /* Rewind file. */fread( d, sizeof( float ), SIZE, fp );     /* Read back data. */     for( n = 0; n < SIZE; ++n )                 /* Print array. */     {printf( "%d: %7.3f\n", n, d[n] );     }fclose( fp );                             /* Close file. */   }

  7. Example

  8. Fgets/ Fputs

  9. Fgets/ Fputs

  10. Block Diagram

  11. Block Diagram

  12. Example

  13. Example

  14. Lessons Learned Freads/Fwrites -Is Binary stream input / output -Use it to save and read -For reading and writing in binary mode, I have learned that there are functions such as fread() and fwrite(). fread() takes a pointer to a location in memory where adequate space has been allocated. -The function fread() reads elements of data, each size bytes long, from the stream pointed to by stream, storing them at the location given by ptr.

  15. Lessons Learned Fgets/Fputs Is Line input / output The function char *gets(char *line) reads the next line of text (i.e. up to the next \n) from the standard input and places the characters (except for the \n) in the character array pointed to by line. The function char *fgets(char *line, int max, FILE *fp) is somewhat more useful. It reads the next line of input from the stream fp and places the characters, including the \n, in the character array pointed to by line. The function int puts(char *line) writes the string pointed to by line to the standard output, and writes a \n to terminate it. The function intfputs(char *line, FILE *fp) writes the string pointed to by line to the stream fp. Like puts, fputs returns a nonnegative value or EOF on error. Unlike puts, fputs does not automatically append a \n.

  16. F I N

More Related