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

时间:2016-05-29 04:30:41

标签: c

我试图从文件

填充struct hashtag数组的hash_name

struct hashtag是

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后,程序停止并出现异常抛出窗口

请帮助

1 个答案:

答案 0 :(得分:2)

这一行是你的问题:

INSERT INTO UsersCompanyTable (userID, companyID)
SELECT * FROM (SELECT $_POST("user_id"), $_POST("company_id")) AS tmp
WHERE NOT EXISTS (
    SELECT companyID FROM UsersCompanyTable WHERE companyID = $_POST("company_id")
) LIMIT 1;

您正在将local = (hashtag*)realloc(local, sizeof(hashtag)); 重新分配到与之前相同的大小。您应该realloc更大的尺寸,而不是相同的尺寸。