S
Susan Sherpi
Hello,
I want to read a line of decimal integers from standard input into an
array, stopping when a newline is encountered, and I'd like the function
to return the number of values read in.
Can someone tell me what's wrong with this function:
----------------------------
int read_array(int p[])
{
j=0;
while(scanf("%d",&p[j])==1)
j++;
return j;
}
----------------------------
I thought that as soon as scanf found a character that wasn't a decimal
number, it wouldn't be able to put it in the array and would return 0, and
I'd bust out of the while loop - but that doesn't happen.
I bet there's a standard library function for this, too - is there?
Thanks -Susan
I want to read a line of decimal integers from standard input into an
array, stopping when a newline is encountered, and I'd like the function
to return the number of values read in.
Can someone tell me what's wrong with this function:
----------------------------
int read_array(int p[])
{
j=0;
while(scanf("%d",&p[j])==1)
j++;
return j;
}
----------------------------
I thought that as soon as scanf found a character that wasn't a decimal
number, it wouldn't be able to put it in the array and would return 0, and
I'd bust out of the while loop - but that doesn't happen.
I bet there's a standard library function for this, too - is there?
Thanks -Susan