[C] 从流中读取一字符串 →→→→→进入此内容的聊天室

来自 , 2020-02-01, 写在 C, 查看 129 次.
URL http://www.code666.cn/view/3dd94242
  1. #include <string.h>
  2. #include <stdio.h>
  3.  
  4. int main ( void )
  5. {
  6.         FILE *stream;
  7.         char string[] = "This is a test";
  8.         char msg[20];
  9.  
  10.         /* open a file for update */
  11.         stream = fopen ( "DUMMY.FIL", "w+" );
  12.  
  13.         /* write a string into the file */
  14.         fwrite ( string, strlen ( string ), 1, stream );
  15.  
  16.         /* seek to the start of the file */
  17.         fseek ( stream, 0, SEEK_SET );
  18.  
  19.         /* read a string from the file */
  20.         fgets ( msg, strlen ( string ) +1, stream );
  21.  
  22.         /* display the string */
  23.         printf ( "%s", msg );
  24.  
  25.         fclose ( stream );
  26.         return 0;
  27. }

回复 "从流中读取一字符串"

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

captcha