strtok wont end!

This is a discussion on strtok wont end! within the C Programming forums, part of the General Programming Boards category; i cant get strtok to end! in all the examples i found it ends but mine wont! i dont see ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    913

    strtok wont end!

    i cant get strtok to end! in all the examples i found it ends but mine wont! i dont see it.

    heres my code
    Code:
    test("-x,-y");
    
    int test(char options[]) {
        char *options_backup = malloc( strlen(options) + 1 );
            strcpy(options_backup, options);
        char *current = strtok (options_backup, ",");
      
        while(current != NULL) {
            printf ("%s\n", current);
            
            current = strtok(NULL, ",");
        }
    
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    That works perfectly fine here, make sureyou #include the appropriate headers.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    And don't forget to free() the memory you've malloc'd
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ISO 8583 Message Parser in C?
    By nadeer78 in forum Projects and Job Recruitment
    Replies: 7
    Last Post: 06-16-2008, 12:56 AM
  2. strtok is causing segmentation fault
    By yougene in forum C Programming
    Replies: 11
    Last Post: 03-08-2008, 09:32 AM
  3. help! Placement of nodes in a Linked List
    By lostmyshadow in forum C Programming
    Replies: 6
    Last Post: 12-17-2007, 12:21 PM
  4. trying to use strtok() function to parse CL
    By ohaqqi in forum C Programming
    Replies: 15
    Last Post: 07-01-2007, 09:38 PM
  5. Next Question...
    By Azmeos in forum C++ Programming
    Replies: 3
    Last Post: 06-06-2003, 02:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21