C语言函数—exec…

函数名

eof

功 能

检测文件结束

用 法

int eof(int *handle);

程序例

#include <sysstat.h> 
#include <string.h> 
#include <stdio.h> 
#include <fcntl.h> 
#include <io.h> 

int main(void) 
{ 
   int handle; 
   char msg[] = "This is a test"; 
   char ch; 

   /* create a file */ 
   handle = open("DUMMY.FIL", 
   O_CREAT | O_RDWR, 
   S_IREAD | S_IWRITE); 

   /* write some data to the file */ 
   write(handle, msg, strlen(msg)); 

   /* seek to the beginning of the file */ 
   lseek(handle, 0L, SEEK_SET); 

   /* 
      reads chars from the file until hit EOF 
   */ 
   do 
   { 
      read(handle, &ch, 1); 
      printf("%c", ch); 
   } while (!eof(handle)); 

   close(handle); 
   return 0; 
} 
  
  

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