How to take input of integers of array and string without knowing the size of the array? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to take input of integers of array and string without knowing the size of the array?

Input 7 6 5 2 1 Output 7 6 5 2 1

18th Aug 2019, 5:44 AM
Geek
Geek - avatar
2 Answers
+ 2
with integer it can't be done, but with string it can be done because we always check for NULL, which gives us advantage to take as many input as we want without knowing the length of the input and without shooting ourselves in the leg, for strings you can use "fgets(pointer,size, stdin); and if you want a user defined length like display the amount of input the user give, you can use the memory allocation function to do that, without wasting memory
18th Aug 2019, 7:11 AM
✳AsterisK✳
✳AsterisK✳ - avatar
0
for integers we can use while(scan("%d ",&a)==1)
18th Aug 2019, 5:33 PM
Geek
Geek - avatar