You need to use some sort of Realloc() function. This function is used to extend the allocated size. The program should be something like that:
- Allocate default value with malloc.
- Read next number from your input.
- If you got the number and this is not EOF (End of file), then use realloc to extend the allocated size by 1 and put the new number at the end.
- Keep doing this untill you reach EOF.
Of course this is just one solution, and there may be others.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…