If i did:
surely there needs to be a loop there otherwise it will only take on phone number then stop.Code:while( ) { for( i = 0 ; i < 15 && ( num[i] = getchar() ) != '.' ; i++ ) num[i] = getchar() ; q = insertnumber( *num, q ) ; }
If i did:
surely there needs to be a loop there otherwise it will only take on phone number then stop.Code:while( ) { for( i = 0 ; i < 15 && ( num[i] = getchar() ) != '.' ; i++ ) num[i] = getchar() ; q = insertnumber( *num, q ) ; }
alright so if I understand you correctly here's an updated version using the while loop.
here loop breaks on end of file; else store input in num until a full stop or out of bounds.
question is what you would do if input has 10 chars only, would you still create a linked list node or break out of the program?Code:int check, i = 0; while ((check = getchar()) != EOF) { if (check != '.' && i < 15) num[i++] = check; else q = insertnumber(*num, q) ; }
Last edited by itCbitC; 12-22-2008 at 11:39 AM.
I'll check your loop out in a sec. Currently im using.
Would that work?Code:while( num[0] != '.' ) { scanf( "%15s", num ) ; if( num[0] != '.' ) q = insertnumber( *num, q ) ; else break ; }
As far as i can see with your loop it wont terminate at a full stop.
Depends what you're looking for in your code, which will exit out only if the first char num[0] is a period but not if the period is in the middle like num[10].
Last edited by itCbitC; 12-22-2008 at 11:54 AM.
From what I have seen, I recommend something like this right now.
It might not be perfect, but you need a coordinated approach to input right now. Given that a full stop is the sentinel value for a loop, we need to do a priming read. If the priming read is successful, then we enter the loop, and only exit the loop when a read fails.Code:int maybe; unsigned area, prefix, exchange; char num[15]; maybe = scanf("(%3u)%3u-%4u", &area, &prefix, &exchange); while (maybe == 3) { sprintf(num, "(%u)%u-%u", area, prefix, exchange); insertnumber(num, q); maybe = scanf("(%3u)%3u-%4u", &area, &prefix, &exchange); } if (scanf("%c", &maybe) == 1 && maybe == '.') { /**success, else do failure operations. **/ }
When the read does fail, we have to read the next character to determine if the reads were successful. For consistency this is done with scanf. I believe the rest is self explanatory. It should be easy enough to code the logical inverse if you only need to do something when the loop fails to read all the input.