How to declare an array with an arbitrary size

后端 未结 4 1598
失恋的感觉
失恋的感觉 2021-01-14 10:32

Ok, this is a C programming homework question. But I\'m truly stuck.

I ask the user to input words, and then I insert the input into an array, but I can\'t have any

4条回答
  •  暖寄归人
    2021-01-14 10:55

    Yes, you want malloc. Checkout this tut.

    http://www.cprogramming.com/tutorial/dynamic_memory_allocation.html

    This site is good in general for learning.

    Here is an example of using realloc, it is basically exactly what you are asking to do.

    http://www.cplusplus.com/reference/clibrary/cstdlib/realloc/

提交回复
热议问题