realloc() invalid old size

后端 未结 5 977
慢半拍i
慢半拍i 2021-02-09 00:09

I am doing an exercise for fun from KandR C programming book. The program is for finding the longest line from a set of lines entered by the user and then prints it.

Her

5条回答
  •  忘了有多久
    2021-02-09 01:10

    Your error is here:

    int _getline(char s[])
    

    It means _getline is a function returning int getting a pointer to char by value.

    You actually want to pass that pointer (which must point to memory allocated with malloc() or be NULL) by reference.

    That means, you need to pass a pointer to a pointer to char.

    Correcting that error will force you to correct all follow-on errors too.

    Only use free / realloc on NULL resp. on pointers returned from malloc, calloc, realloc or a function specified to return such a pointer.

提交回复
热议问题