鱼C论坛

 找回密码
 立即注册
查看: 4750|回复: 1

麻烦大佬们帮我看看我这释放空间对不对

[复制链接]
发表于 2022-4-19 23:11:46 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
typedef struct Account
{
        char cardNum[17];
        char password[7];
        char userName[10];
        char balance[20];
        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;
        }
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-9-3 15:17:40 | 显示全部楼层
没问题,测试过了,可以运行
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-7 12:27

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表