C语言函数—fgetchar

函数名

fgetc

功 能

从流中读取字符

用 法

int fgetc(FILE *stream);

程序例

#include <string.h> 
#include <stdio.h> 
#include <conio.h> 

int main(void) 
{ 
   FILE *stream; 
   char string[] = "This is a test"; 
   char ch; 

   /* open a file for update */ 
   stream = fopen("DUMMY.FIL", "w+"); 

   /* write a string into the file */ 
   fwrite(string, strlen(string), 1, stream); 

   /* seek to the beginning of the file */ 
   fseek(stream, 0, SEEK_SET); 

   do 
   { 
      /* read a char from the file */ 
      ch = fgetc(stream); 

      /* display the character */ 
      putch(ch); 
   } while (ch != EOF); 

   fclose(stream); 
   return 0; 
} 
  
  
  

如果引用本站的原创文章,请注明原文链接:,本站保留追究责任的权利!
评论已关闭。