我试图从文件
填充struct hashtag数组的hash_namestruct 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后,程序停止并出现异常抛出窗口
请帮助
答案 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
到更大的尺寸,而不是相同的尺寸。