|
|
|
|
|||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
sscanf question
Given the following
#include <stdio.h> int main(void) { char line[BUFSIZ]; long arg1, arg2; while(fgets(line, BUFSIZ, stdin) != NULL){ if(sscanf(line,"%ld%ld",&arg1,&arg2) == 2){ snprintf(line, sizeof(line), "%ld\n", arg1 + arg2); if(fputs(line, stdout) == EF){ fprintf(stderr, "output error\n"); } } else{ fprintf(stderr, "invalid input\n"); } } return 0; } When I run it, I get the following [cdalten@localhost oakland]$ ./add 4 5 9 65 invalid input Now, here's the question. How come there has to be a space between the numbers? sscanf() in this case doesn't even have a space in the format args. Ie, it is like the following (sscanf(line,"%ld%ld",&arg1,&arg2) More to the point. How come when I enter 65, the computer won't spit back 11? |
![]() |
| Viewing: Web Development Archives > FAQs > C/C++ > sscanf question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|