Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- gcc -std=c99 -Wall -o main main.c
- */
- #include <stdio.h>
- #include <stdlib.h>
- #define LEN 1024
- void readwrite(char *rfile, char *wfile){
- FILE *fpr, *fpw;
- char str[LEN];
- /* чтение значений */
- if((fpr=fopen(rfile, "rb"))==NULL) {
- printf("Не удаётся отрыть файл %s.\n", rfile);
- exit(1);
- }
- /* запись значений */
- if((fpw=fopen(wfile, "wb"))==NULL) {
- printf("Не удаётся отрыть файл %s.\n", wfile);
- exit(1);
- }
- while(!feof(fpr)){
- if(fgets(str, LEN, fpr)){
- /*
- * Тут что-нибудь делам с str.
- */
- fputs(str, fpw);
- printf("%s", str);
- }
- }
- if(fclose(fpr)){
- printf("Ошибка при закрытии файла %s.\n", rfile);
- }
- if(fclose(fpw)){
- printf("Ошибка при закрытии файла %s.\n", wfile);
- }
- }
- int main(int argc, char **argv)
- {
- readwrite(argv[1], argv[2]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement