生活随笔
收集整理的這篇文章主要介紹了
库函数和 系统调用
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1:系統(tǒng)調(diào)用
#include<fcntl.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>
#include<stdio.h>#define BUFFER_SIZE 100
char * str_a
= "C:\\Users\\jiang000\\CLionProjects\\systemCall\\a";
char * str_b
= "C:\\Users\\jiang000\\CLionProjects\\systemCall\\b";int main(){int a_fd
= open(str_a
,O_RDONLY
);printf("%d",a_fd
);long size
= lseek(a_fd
,0,SEEK_END);long half_size
= size
/ 2;long res
= lseek(a_fd
,-half_size
,SEEK_END);int b_fd
= open(str_b
,O_WRONLY
);printf("%d",b_fd
);printf("woshi: %d",stdin);char buffer
[BUFFER_SIZE
];int read_cnt
;while((read_cnt
= read(a_fd
,buffer
,BUFFER_SIZE
)) > 0){write(b_fd
,buffer
,read_cnt
);}printf("bei bei");close(a_fd
);close(b_fd
);
}
2:庫函數(shù)
#include<stdio.h>void showdiff(char *file1
,char * file2
, char *file3
);
int main(){printf("hello beibei\n");showdiff("C:\\Users\\jiang000\\CLionProjects\\helloWorld\\1.txt","C:\\Users\\jiang000\\CLionProjects\\helloWorld\\2.txt","C:\\Users\\jiang000\\CLionProjects\\helloWorld\\3.txt");
printf("hello ");
}void showdiff(char *file1
,char * file2
, char *file3
){FILE
* fp1
= 0, *fp2
= 0, * fp3
= 0;char ch1
,ch2
;fp1
= fopen(file1
,"r");fp2
= fopen(file2
,"r");fp3
= fopen(file3
,"w");while(1){ch1
= (char) fgetc(fp1
);ch2
= (char) fgetc(fp2
);if(feof(fp1
) or
feof(fp2
)){break;}if(ch1
== ch2
){printf("%c \n",ch1
);fputc(ch1
,fp3
);}}fclose(fp1
);fclose(fp2
);fclose(fp3
);
}
3:相關(guān)知識
- #define stdin (__acrt_iob_func(0))
- #define stdout (__acrt_iob_func(1))
- #define stderr (__acrt_iob_func(2))
總結(jié)
以上是生活随笔為你收集整理的库函数和 系统调用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。