实在不知道问题出在哪,请大家帮我看看
#include<stdio.h>#include<stdlib.h>
#include<string.h>
int main(void)
{
FILE *f1;
char *f2;
char s[100];
long length;
char mode;
if ((f1 = fopen("infomation.txt", "r+")) == NULL)
{
printf("Can't open file.\n");
exit(EXIT_FAILURE);
}
fseek(f1, 0, SEEK_END);
length = ftell(f1);
f2 = (char*)malloc(sizeof(char)*length);
rewind(f1);
while (fgets(s, 100, f1) != NULL)
{
printf("%s\n", s);
printf("d or c or u?\n");
if ((mode = getchar()) == 'u')
strcat(f2, s);
else if (mode == 'c')
{
printf("Enter new information.\n");
fgets(s, 100, stdin);
strcat(f2, s);
}
else if (mode == 'd')
continue;
while (getchar() != '\n');
}
printf("success.\n"); //第一个success可以显示
if (fclose(f1) != 0)
{
printf("Close failed.\n");
exit(EXIT_FAILURE);
}
printf("success.\n"); //第二个success不可以显示
if ((f1 = fopen("infomation.txt", "w+")) == NULL)
{
printf("Can't open file.\n");
exit(EXIT_FAILURE);
}
fputs(f2, f1);
fclose(f1);
return 0;
}
我觉得问题可能出在fclose(f1);但是,实在看不出来有什么问题
[ 本帖最后由 ujszmc 于 2015-5-13 11:23 编辑 ]