Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在project.exe中的0x5409B211(ucrtbased.dll)处引发异常:0xC0000005:访问冲突写入位置0x007110E8_C - Fatal编程技术网

在project.exe中的0x5409B211(ucrtbased.dll)处引发异常:0xC0000005:访问冲突写入位置0x007110E8

在project.exe中的0x5409B211(ucrtbased.dll)处引发异常:0xC0000005:访问冲突写入位置0x007110E8,c,C,我试图从一个文件中填充struct hashtag数组的hash_名称 结构hashtag是 typedef struct{ char hash_name[300]; long hash_freq; ID_liste users; }hashtag; 我的functin是 void load_hashtag(long ID,int* taille,hashtag *local) { int i=-1; char filename[100]; sprint

我试图从一个文件中填充struct hashtag数组的hash_名称

结构hashtag是

typedef struct{
    char hash_name[300];
    long hash_freq;
    ID_liste users;
}hashtag;
我的functin是

 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));

您正在将本地重新分配到与以前相同的大小。您应该使用更大的大小,而不是相同的大小。

使用调试器。OT:这。。。fn\\%d.名称,ID;应该是。。。fn\\%ld.featnames,ID;因为ID是长的。@ MuHaMaMyHyddIn——如果这个答案有助于解决你的问题,请考虑使用投票箭头下的复选标记。非常感谢。