fd (int)读写文件

#include <string.h>
#include <stdio.h>
#include <fcntl.h>
int main()
{
  char *p1 = "This is a c test code";
  volatile int len = 0;
 
  int fp = open("/home/test.txt", O_RDWR|O_CREAT);
  for(;;)
  {
     int n;
 
     if((n=write(fp, p1+len, (strlen(p1)-len)))== 0)   //if((n=write(fp, p1+len, 3)) == 0) 
     {                                                 //strlen(p1) = 21
         printf("n = %d \n", n);
         break;
     }
     len+=n;
  }
  return 0;
}
 

  原文链接:https://blog.csdn.net/hhhlizhao/article/details/71552588

猜你喜欢

转载自www.cnblogs.com/hshy/p/12014215.html
fd