Scanf array limit in C? -
i have little error in c:
error: look must have constant value
i know, that's mean limit must have constant value, how can solve when have situation?
printf("type limit: "); scanf("%i",&limit); int arr[limit];
thanks.
edit:
ok guys, problem, sorry if spam.
int num,limit,i; printf("type limit: "); scanf("%i",&limit); int *arr = (int*)malloc(limit*sizeof(int)); for(i=0;i<limit;i++) { printf("type num %i: ",i); arr[i] = scanf("%i",&num); } system("pause"); homecoming 0;
error 4 error c2109 subscript requires array or pointer type
you should utilize malloc
:
printf("type limit: "); scanf("%i",&limit); int *arr = malloc(sizeof(int) * limit);
c arrays scanf variable-length-array
No comments:
Post a Comment