Skip to content

Instantly share code, notes, and snippets.

@aprell
Created July 3, 2013 18:42
Show Gist options
  • Select an option

  • Save aprell/5921527 to your computer and use it in GitHub Desktop.

Select an option

Save aprell/5921527 to your computer and use it in GitHub Desktop.
Scansets in input format strings
#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