我在从行分隔的文本文件中加载一些代码时遇到了一些问题,该文件的格式如下:
aa
bb
dd
ccasdf
dfdsafefasd
vdasfeadsaf
cvdasegfdjasflfe
swedtd
对于一个数组,我只想得到一个包含文本文件中所有内容的数组......这是我的代码:
#include<stdio.h>
#include<string.h>
int main()
{
int size = 0;
char peeps[10000][50];
FILE *people = fopen("test.txt","r");
while(fscanf(people,"%s",peeps[size]) != EOF)
{
size++;
}
fclose(people);
return 0;
}
当我运行它时,我得到一个段错误,我查看了 gdb 吐出的内容,但我不知道如何修复它......这是 gdp 打印出来的:
Program received signal SIGSEGV, Segmentation fault.
_IO_vfscanf_internal (s=s@entry=0x804a008, format=format@entry=0x804865f "%s", argptr=argptr@entry=0xbff85298 "4X\305I",
errp=errp@entry=0x0) at vfscanf.c:1073
1073 *str++ = c;
(gdb) bt
#0 _IO_vfscanf_internal (s=s@entry=0x804a008, format=format@entry=0x804865f "%s",
argptr=argptr@entry=0xbff85298 "4X\305I", errp=errp@entry=0x0) at vfscanf.c:1073
#1 0xb7e5564d in __isoc99_fscanf (stream=0x804a008, format=0x804865f "%s") at isoc99_fscanf.c:35
#2 0x08048581 in main () at fdsa.c:10
有谁知道出了什么问题???