root@ubuntu:/my# ./fun jpeglib.h jpeg.h
44444
Segmentation fault (core dumped)
下面是源码
root@ubuntu:/my# cat 2.c
#include
int main(int argc, char **argv)
{
FILE *fp1, *fp2;
char buff[124];
char buff1[124];
char *temp;
int i = 0;
if((fp1 = fopen(argv[1], "r")) == NULL){
printf("can not open file %s\n", argv[1]);
return -1;
}
if((fp1 = fopen(argv[2], "wa+")) == NULL){
printf("can not open file %s\n", argv[2]);
return -1;
}
printf("44444\n");
while(fgets(buff, 124, fp1) != NULL){
printf("-------------\n");
temp = buff;
printf("++\n");
while(*temp++ != '0'){
buff1[i] = buff[i+1];
i++;
printf("%d\n", i);
}
fputs(buff1, fp2);
}
fclose(fp1);
fclose(fp2);
return 0;
}