   C Program problems
  when the user input value like (1, 2, 3, 4, 5, 6, 18).i want to separate to 1 2 3 4 5 6 18when i use the sscanf(value, "%d %d ...", &num, &num), it must know how many , are here and create the variable.have any other methods that can separate the string when i don't know how many , are here?   
  Why not just accept the user input as a string and then parse that string?  (During parsing, every time you come across a ',' you know there will be another number following that ',').   ;Quote:Original post by MikeTacularWhy not just accept the user input as a string and then parse that string?  (During parsing, every time you come across a ',' you know there will be another number following that ',').how can i do it?   ;Quote:Original post by anguspangQuote:Original post by MikeTacularWhy not just accept the user input as a string and then parse that string?  (During parsing, every time you come across a ',' you know there will be another number following that ',').how can i do it?Which part can't you do? Can you read in a string? Do you understand how to parse something? Have you any code that you've tried?   ;  Here's  a simple example that should get you started:char str[1024];char *cur;int i;fgets(str, 1024, stdin ); // Read a string from standard in up to 1023 chars.cur = strtok(str, " \t"); // Start cutting up the string "str" on spaces and tabsi = 1;while (cur) {    int num = atol(cur);  // Convert current string as a number    printf("Number %d is %d\n", i, num);    i++;    cur = strtok(NULL, " \t"); // Keep cutting up "str" on space/tabs.  strtok remembers the original str passed in the first time.}Note that you will probably want to use strtol() and check the validity of the string (make sure it's a number), or if you know you won't be given bad input like  myapp 1 2 3 4 !()@#(@_!, then you can just do it that way.Hope that helps!   ;Quote:Original post by rethanHere's  a simple example that should get you started:char str[1024];char *cur;int i;fgets(str, 1024, stdin ); // Read a string from standard in up to 1023 chars.cur = strtok(str, " \t"); // Start cutting up the string "str" on spaces and tabsi = 1;while (cur) {    int num = atol(cur);  // Convert current string as a number    printf("Number %d is %d\n", i, num);    i++;    cur = strtok(NULL, " \t"); // Keep cutting up "str" on space/tabs.  strtok remembers the original str passed in the first time.}Note that you will probably want to use strtol() and check the validity of the string (make sure it's a number), or if you know you won't be given bad input like  myapp 1 2 3 4 !()@#(@_!, then you can just do it that way.Hope that helps!but i have more question, how can i store into array?whne i put an arrayabc = cur; it is error...i want to store in arraybecause i will use the stncmp(value, abc, 4 ) later...;  Your errors depend entirely on the rest of your source. What is the type of "abc"? What error message does your compiler emit?   ;Quote:Original post by anguspang...but i have more question, how can i store into array?whne i put an arrayabc = cur; it is error...i want to store in arraybecause i will use the stncmp(value, abc, 4 ) later...rip-off is correct, we'd need to know more about what you are trying to do in order to help.  Do you want to store the strings in an array, or the integer values?  If you want to store the values you'll need to do somethng like this:int abc[MAX_VALUES];while (cur)    {    int num = atol(cur); // Convert current string as a number    abc = num;    printf("Number %d is %d\n", i, num);    i++;    cur = strtok(NULL, " \t"); // Keep cutting up "str" on space/tabs. strtok remembers the original str passed in the first time.    }instead.   