fork(4) download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(void) {
  5. const char my_string[] = "[1,2,3,4,5]";
  6. const char *curr = &my_string[1];
  7. while (curr != NULL) {
  8. int tmp;
  9. sscanf(curr, "%d", &tmp);
  10. printf("%d\n", tmp);
  11.  
  12. /* find next comma */
  13. curr = strchr(curr, ',');
  14.  
  15. /* if a comma was found, go to next integer */
  16. if (curr)
  17. curr += 1;
  18. }
  19. return 0;
  20. }
  21.  
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
1
2
3
4
5