C语言函数—realloc

函数名

read

功 能

从文件中读

用 法

int read(int handle, void *buf, int nbyte);

程序例

#include <stdio.h> 
#include <io.h> 
#include <alloc.h> 
#include <fcntl.h> 
#include <process.h> 
#include <sysstat.h> 

int main(void) 
{ 
   void *buf; 
   int handle, bytes; 

   buf = malloc(10); 

/* 
   Looks for a file in the current directory named TEST.$$$ and attempts 
   to read 10 bytes from it.  To use this example you should create the 
   file TEST.$$$ 
*/ 
   if ((handle = 
      open("TEST.$$$", O_RDONLY | O_BINARY, S_IWRITE | S_IREAD)) == -1) 
   { 
      printf("Error Opening Filen"); 
      exit(1); 
   } 

   if ((bytes = read(handle, buf, 10)) == -1) { 
      printf("Read Failed.n"); 
      exit(1); 
   } 
   else { 
      printf("Read: %d bytes read.n", bytes); 
   } 
   return 0; 
} 
  
  

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