[C] 从一个流中读数据 →→→→→进入此内容的聊天室

来自 , 2019-06-23, 写在 C, 查看 117 次.
URL http://www.code666.cn/view/d5e2c0ad
  1. #include <string.h>
  2. #include <stdio.h>
  3.  
  4. int main ( void )
  5. {
  6.         FILE *stream;
  7.         char msg[] = "this is a test";
  8.         char buf[20];
  9.  
  10.         if ( ( stream = fopen ( "DUMMY.FIL", "w+" ) )
  11.                 == NULL )
  12.         {
  13.                 fprintf ( stderr,
  14.                           "Cannot open output file.\n" );
  15.                 return 1;
  16.         }
  17.  
  18.         /* write some data to the file */
  19.         fwrite ( msg, strlen ( msg ) +1, 1, stream );
  20.  
  21.         /* seek to the beginning of the file */
  22.         fseek ( stream, SEEK_SET, 0 );
  23.  
  24.         /* read the data and display it */
  25.         fread ( buf, strlen ( msg ) +1, 1, stream );
  26.         printf ( "%s\n", buf );
  27.  
  28.         fclose ( stream );
  29.         return 0;
  30. }
  31.  

回复 "从一个流中读数据"

这儿你可以回复上面这条便签

captcha