Created
July 3, 2013 18:42
-
-
Save aprell/5921527 to your computer and use it in GitHub Desktop.
Scansets in input format strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| typedef struct person { | |
| char firstname[20]; | |
| char lastname[20]; | |
| unsigned int age; | |
| } Person; | |
| int main(void) | |
| { | |
| Person people[3]; | |
| char line[100]; | |
| int i; | |
| for (i = 0; i < 3; i++) { | |
| Person *p = &people[i]; | |
| fgets(line, sizeof(line), stdin); | |
| if (sscanf(line, "%19[^,],%19[^,],%u", p->lastname, p->firstname, &p->age) == 3) | |
| printf("%s %s, %u\n", p->firstname, p->lastname, p->age); | |
| else | |
| printf("Failed to scan\n"); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment