linux中关于fgets函数段错错

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;

}

你的fp2为空啊,没有打开啊。你fp1打开了两次。
还有啊,干嘛这么麻烦呢?参考下面的代码:
while(fgets(buff, 124, fp1) != NULL){
fputs(buff1, fp2);

}
这样多好,你是想把.h文件内容复制到第二个.h中吧?

同学问题解决了吗?如果有解决请采纳一下。