fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <string.h>
  4. #include <limits.h>
  5. #include <stdlib.h>
  6.  
  7. // apparently, this isn't in limits.h in ideone's implementation
  8. #define LINE_MAX 1024
  9.  
  10. int main()
  11. {
  12. char buf[LINE_MAX];
  13. fgets(buf, sizeof(buf), stdin);
  14. const char *lparen = strchr(buf, '(');
  15. const char *comma = strchr(lparen + 1, ',');
  16. // const char *rparen = strchr(comma + 1, ')'); // is this even needed?
  17.  
  18. char str[lparen - buf + 1];
  19. memcpy(str, buf, lparen - buf);
  20. str[lparen - buf] = 0;
  21. int n1 = strtol(lparen + 1, NULL, 10);
  22. int n2 = strtol(comma + 1, NULL, 10);
  23.  
  24. printf("string: %s\nNumbers: %d and %d\n", str, n1, n2);
  25.  
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 1836KB
stdin
foo bar baz (42, 1337)
stdout
string: foo bar baz 
Numbers: 42 and 1337