fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4.  
  5. int main(void){
  6. // save input into a string
  7. char str[100];
  8. int coefficients[101], j=0;
  9. printf("enter number sep by commas:\n");
  10. scanf("%99s", str);
  11.  
  12. // get the first number (token)
  13. char *token;
  14. token = strtok(str, ",");
  15. int i;
  16. while (token != NULL){
  17. // convert the number into an integer (since its initially a char)
  18. i = atoi(token);
  19.  
  20. // I want to store i in another array
  21. coefficients[j++]=i;
  22.  
  23. // get next number after the comma
  24. token = strtok(NULL, ",");
  25. }
  26. printf("%d\n", coefficients[0]);
  27. printf("%d\n", coefficients[1]);
  28. }
Success #stdin #stdout 0s 2116KB
stdin
1,20,31,42
stdout
enter number sep by commas:
1
20