麻烦大佬们帮我看看我这释放空间对不对
typedef struct Account{
char cardNum;
char password;
char userName;
char balance;
struct Account* next;
}LIST;
LIST* head=NULL;
LIST* p = NULL;
void initialize() {
FILE* fp;
LIST* tail,*temp;
head = (LIST*)malloc(sizeof(LIST));
tail = head;
p = head;
if ((fp = fopen("D:\\华软2021-2022\\c2\\ATM模拟机\\accounts.txt", "r")) == NULL) {
printf("文件打开错误");
exit(0);
}
while (1) {
temp = (LIST*)malloc(sizeof(LIST));
fscanf(fp, "%s\t%s\t%s\t%s\n", temp->cardNum, temp->password, temp->userName, temp->balance);
temp->next = NULL;
tail->next = temp;
tail = temp;
if (feof(fp)) {
break;
}
}
fclose(fp);
}
void freeSpace() {
LIST* temp = p->next;
while (temp!=NULL) {
p = temp->next;
free(temp);
temp = p;
}
} 没问题,测试过了,可以运行{:5_109:}
页:
[1]