0

Is it possible to dynamically use scanf to prompt for user input ? I have the code shown below

scanf("%d %d %d %d", &myarray[row][0], &myarray[row][1], &myarray[row][2], &myarray[row][3])

which works fine when the number of columns is fixed but in my case it is not !

4
Contributors
3
Replies
17
Views
3 Years
Discussion Span
Last Post by Akash_Soni
0

Search for malloc, calloc and realloc functions. The only issues with malloc and calloc is if you don't know the maximum size of your dynamic array, but you can always try with realloc and allocate byte by byte(try to input, check if there is space, if not - reallocate memory by adding one more)

0

Ya you can use loop for iteration upto the number of columns and then u can acheive it just like this

for(i = 0;i < col;i++)
    scanf("%d",&myarray[row][i]);

and for dynamic allocation of column you can use malloc or calloc function.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.