鱼C论坛

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

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

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

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

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

x
  1. typedef struct Account
  2. {
  3.         char cardNum[17];
  4.         char password[7];
  5.         char userName[10];
  6.         char balance[20];
  7.         struct Account* next;
  8. }LIST;
  9. LIST* head=NULL;
  10. LIST* p = NULL;


  11. void initialize() {
  12.         FILE* fp;
  13.         LIST* tail,*temp;
  14.         head = (LIST*)malloc(sizeof(LIST));
  15.         tail = head;
  16.         p = head;

  17.         if ((fp = fopen("D:\\华软2021-2022\\c2\\ATM模拟机\\accounts.txt", "r")) == NULL) {
  18.                 printf("文件打开错误");
  19.                 exit(0);
  20.         }

  21.         while (1) {
  22.                 temp = (LIST*)malloc(sizeof(LIST));
  23.                 fscanf(fp, "%s\t%s\t%s\t%s\n", temp->cardNum, temp->password, temp->userName, temp->balance);
  24.                 temp->next = NULL;
  25.                 tail->next = temp;
  26.                 tail = temp;
  27.                 if (feof(fp)) {
  28.                         break;
  29.                 }
  30.         }
  31.         fclose(fp);
  32. }



  33. void freeSpace() {
  34.         LIST* temp = p->next;
  35.         while (temp!=NULL) {
  36.                 p = temp->next;
  37.                 free(temp);
  38.                 temp = p;
  39.         }
  40. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-9-3 15:17:40 | 显示全部楼层
没问题,测试过了,可以运行
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-14 19:10

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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