【发布时间】:2022-10-06 17:39:48
【问题描述】:
我必须使用学生列表文件进行线性搜索。
该文件按年份排序。我必须从文件中接收年份、学生姓名。如果名称相同,我必须将频率添加到freq[]。如果是不同的名字,可以在数组末尾添加一个学生姓名结构。当我在 Ubuntu 中运行 gdb 时,我可以编译它,但是当我添加频率时,我不断收到错误。
In particular, this part produces a segmentation fault. If I annotated this line, there is no segmentation fault, but the execution does not stop.
Structure is here.
请帮我
-
Step 1. 检查第一个
fscanf(fp, \"%d %s %c %d %*c\", &year, buff.name, &(buff.sex), &count)的返回值,看是否为4。 2) 添加宽度限制%s-->%19s3)if(rs == EOF) break;-->if(rs != 4 EOF) break; -
同时显示minimal reproducible example。并考虑投入大约一个小时来学习调试器的基础知识,这是查找此类错误的完美工具。
-
me_river,代码未显示在过去之前如何分配
names。发布minimal reproducible example/ -
我猜
names->data有空间容纳names->capacitytNames。当names->len超过names->capacity-1时,你需要realloc吗? -
我的意思是你确实打电话给
realloc,但当时容量可能已经超出了。
标签: arrays c sorting segmentation-fault linear-search