fork download
  1. #include <stdio.h>
  2. #include <errno.h>
  3. #include <stdlib.h>
  4. #define MAXLEN 100
  5. int main(void)
  6. {
  7. char pp[MAXLEN+1];
  8. if(fgets(pp,MAXLEN+1,stdin) == NULL ){
  9. fprintf(stderr,"Error in input");
  10. exit(EXIT_FAILURE);
  11. }
  12. char *ptr = pp;
  13. char *end;
  14. long i = strtol(ptr, &end, 10);
  15. while( ptr != end )
  16. {
  17. ptr = end;
  18. if (errno == ERANGE){
  19. printf("range error, got ");
  20. errno = 0;
  21. }
  22. printf("Got - %ld\n", i);
  23. /* work with i */
  24. i = strtol(ptr, &end, 10);
  25. }
  26. return 0;
  27. }
Success #stdin #stdout 0s 4296KB
stdin
10 20 34
stdout
Got - 10
Got - 20
Got - 34