fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(void) {
  5. char line[] = "Foo Bar 42";
  6. {
  7. char name[30];
  8. int age;
  9. char *space = strrchr(line, ' ');
  10. if (!space) /* error, bad line */;
  11. if (space - line >= 30) /* error, name too long */;
  12. sprintf(name, "%.*s", space - line, line);
  13. age = strtol(space, NULL, 10); // needs error checking
  14. // ...
  15. printf("[%s]; %d\n", name, age);
  16. }
  17. return 0;
  18. }
  19.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
[Foo Bar]; 42