I have to input an array of integers. The length of this array is determined at runtime when the user hits some sentinal key (likely I'll use return)
//input path to be analyzed
int n = 0;
while(scanf("%d",&input[n])==1){
//??
}
}
Input:
Then these values are stored in the array a as:
I also need proper error checking of course.
This is a basic problem im sure however I'm unable to solve it.
Thanks!
Im thinking ill need a while loop however im unsure how to use scanf to both terminate the loop, initilize the array and input the values.
You can do it as follows:
int main()
{
char ch;
int i=0;
int input[100000]; //Or dynamically allocate
while(scanf("%c",&ch) && (ch!='\n')){
if(ch==' ') continue;
input[i++]=ch - '0';
printf("%d ",input[(i-1)]);
}
}