我正在尝试从文件中填充 struct hashtag 数组的 hash_name
结构主题标签是
typedef struct{
char hash_name[300];
long hash_freq;
ID_liste users;
}hashtag;
我的功能是
void load_hashtag(long ID,int* taille,hashtag *local)
{
int i=-1;
char filename[100];
sprintf(filename, "data\\fn\\%d.featnames", ID);
long a;
FILE * g=fopen(filename,"r");
do{
if (i >= 0)
{
local = (hashtag*)realloc(local, sizeof(hashtag));
printf("realloc %d\n", i);
}
i++;
fscanf(g,"%ld",&a); //a numbre i don't want
fseek(g, 2, SEEK_CUR); //tow characters i don' want
fscanf(g, "%s", local[i].hash_name);
}while(!feof(g));
fclose(g);
*taille = i;
}
主要是
int main()
{
int i,j;
hashtag* local = (hashtag*)malloc(sizeof(hashtag));
int local_taille;
long ID_user;
FILE* user;
user = fopen("User.txt", "r");
if (user == NULL)
{
printf("Error opening file\n");
return 0;
}
fscanf(user, "%ld", &ID_user);
load_hashtag(ID_user,&local_taille,local);
fclose(user);
system("Pause");
return 0;
}
从 1300 到 50 fscanf 后,程序停止并出现异常抛出窗口
请帮忙
最佳答案
这一行是你的问题:
local = (hashtag*)realloc(local, sizeof(hashtag));
您正在将 local
重新分配为之前的大小。你应该realloc
到更大尺寸,而不是相同尺寸。
关于c - 在project.exe : 0xC0000005: Access violation writing location 0x007110E8 中的0x5409B211 (ucrtbased.dll)处抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37506182/