copy文档
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(int argc, const char *argv[])
{
if (argc != 3)
{
printf("error\n");
printf("./a.out dest scr\n");
}
FILE* scr;
if((scr = fopen(argv[1],"a+") )== NULL)
{
perror("file fail");
return -1;
}
FILE* dest;
if ((dest = fopen(argv[2],"w")) == NULL)
{
perror("file fail");
return -1;
}
char brr[1024];
fgets(brr,sizeof(brr),scr);
brr[sizeof(brr)-1] = '\0';
fputs(brr,dest);
fclose(scr);
fclose(dest);
return 0;
}
计算空格行
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(int argc, const char *argv[])
{
if (argc != 2)
{
printf("error\n");
printf("./a.out new");
return -1;
}
FILE *fp;
if((fp = fopen(argv[1],"r")) == NULL)
{
perror("file error");
return -1;
}
char brr[1024];
int count = 0;
while ( fgets(brr,sizeof(brr),fp) != NULL)
{
if (brr[strlen(brr)-1] == '\n')
count++;
}
fclose (fp);
printf("一共多少行%d",count);
return 0;
}