fork download
  1. #include <cstdio>
  2.  
  3. int main()
  4. {
  5. char s[256], *p;
  6. int x;
  7. int n;
  8.  
  9. fgets(s, sizeof s, stdin);
  10.  
  11. // add n after check p to allow last iteration when the number is at the end
  12. for (p=s; sscanf(p, "%*[^-0-9]%n", &(n=0)), sscanf(p+=n, "%d%n", &x, &(n=0)), *p; p+=n)
  13. if (n)
  14. printf("%d ", x);
  15. else
  16. ++p; // skip '-'
  17.  
  18. return 0;
  19. }
Success #stdin #stdout 0s 16064KB
stdin
12uhjkhjkl-77jklvjld78msla kdsjfl 66 14m,434,,,42-88--16
stdout
12 -77 78 66 14 434 42 -88 -16