realloc():次のサイズが無効です...エラー



Realloc Invalid Next Size



著者:SuperDeveloper
日付:2018/1/2

The realloc function is used in the program to change the size of the structure array. The error code is as follows: struct point * p=(struct point *)malloc(10) ............ while(1){ ............................ p=realloc(p,new_size) //new_size is about 224*sizeof(struct point) .......................... }

結果はエラーです:realloc():invalid next size



主な理由は、構造体配列が初期化されるときに、mallocによって指定されたサイズがreallocによって指定されたサイズと大きく異なるためです。次のように変更します。

struct point * p=(struct point *)malloc(224*sizeof(struct point *))

コンパイルするだけ