IO day3作业

1.

1 #include 
  2 #include 
  3 #include 
  4 #include 
  5 int main(int argc, const char *argv[])
  6 {
  7     int a;
  8     a=open("tp.png",O_RDWR | O_CREAT | O_TRUNC,0777);
  9     int c;
 10     c=open("/home/ubuntu/Pictures/2023-07-31 14-59-13 的屏幕截图.png",O_RDONLY);
 11     if(a<0)
 12     {                                                                                                                                                                                                                               
 13         ERR_MSG("open");
 14         return -1;
 15     }
 16     printf("执行成功\n");
 17     int res;
 18     long sum=0;
 19     char b[100];
 20     while(1)
 21     {
 22         bzero(b,sizeof(b));
 23         res = read(c,b,sizeof(b));
 24         sum+=res;
 25         if(0 == res)
 26         {
 27             break;
 28         }
 29         write(a,b,res);
 30     }
 31     printf("文件大小:%ld\n",sum);
 32     if(close(a)<0)
 33     {
 34         ERR_MSG("close");
 35         return -1;
 36     }
 37     if(close(c)<0)
 38     {
 39         ERR_MSG("close");
 40         return -1;
 41     }
 42     printf("关闭成功\n");
 43     return 0;
 44 }

2.

1 #include 
  2 #include 
  3 #include 
  4 #include 
  5 void qx(mode_t m)
  6 {
  7     int a=0400;
  8     for(int i=1;i<4;i++)
  9     {
 10         if(m & a) 
 11             printf("r");
 12         else
 13             {printf("-");}
 14         m=m<<1; 
 15         if(m & a)
 16             printf("w");
 17         else
 18         {printf("-");}
 19         m=m<<1;
 20         if(m & a)
 21             printf("x");
 22         else
 23         {printf("-");}                                                                                                                    
 24         m=m<<1;
 25     }   
 26 printf(" ");
 27 }
 28 void sj(time_t t)
 29 {
 30     struct tm *info=localtime(&t);
 31     printf("%d-%02d-%02d %02d:%02d:%02d ",\
 32             info->tm_year+1900,info->tm_mon+1,\
 33             info->tm_mday,info->tm_hour,info->tm_min,\                                                                                    
 34             info->tm_sec);
 35 }
 36 int main(int argc, const char *argv[])
 37 {
 38     struct stat buf;
 39     if((stat("1.c",&buf))<0)
 40     {
 41         ERR_MSG("stat");
 42         return -1;
 43     }
 44     printf("dev=%ld\n",buf.st_dev);
 45     printf("ino=%ld\n",buf.st_ino);
 46     qx(buf.st_mode);
 47     printf("%ld ",buf.st_nlink);
 48     printf("%d ",buf.st_uid);
 49     printf("%d ",buf.st_gid);
 50     printf("%ld ",buf.st_size);
 51     sj(buf.st_mtime);
 52     printf("1.c\n");
 53     return 0;
 54 }

3.xmid

IO day3作业_第1张图片

 

你可能感兴趣的:(c语言)