Thread: trying to use strtok

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    6

    trying to use strtok

    i am a beginner in C programming, and i appreciate any help with strtok. what i wanna do is for the program to scan the data, and whenever it encounters the alphabet "l", the section before the alphabet "l" would be copied to a string array. for instance,
    Code:
    #include <stdio.h>
    #include <string.h>
    main ()
    {
     char *b;
      int i,;
      char s[100];
      char data[100];
    
      strcopy(data,"asdldsaldsal");
    
      for(i=0;i<=2;i++)
        {
          b = strtok (data,'l');
          s[i]=b;
     
      if (s[i]==NULL)
        break;
        }  
     printf("s[1]=",s[1]);
    
      return 0;
    }
    why doesnt it run? thank you for your attention...

    sincerely
    gwmexod

  2. #2
    Awesomefaceradcore bivhitscar's Avatar
    Join Date
    Apr 2006
    Location
    Melbourne, Australia
    Posts
    210
    Look up the function usage for strtok. The first call passes a pointer, but subsequent calls require the passing of NULL.

    There is also no function strcopy, you were looking for strcpy.

    I'd suggest starting with simpler programs before diving into arrays and pointers.
    Last edited by bivhitscar; 06-04-2006 at 09:38 PM.
    it's ironic considerate rarity patron of love higher knowledge engulfs me...

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    6
    thank you for pointing out the error... quite embarrassed to have asked such simple question... appreciate it

  4. #4
    Awesomefaceradcore bivhitscar's Avatar
    Join Date
    Apr 2006
    Location
    Melbourne, Australia
    Posts
    210
    It's not the simplest of questions though, I find using strtok() a bit annoying somtimes.
    it's ironic considerate rarity patron of love higher knowledge engulfs me...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 20q game problems
    By Nexus-ZERO in forum C Programming
    Replies: 24
    Last Post: 12-17-2008, 05:48 PM
  2. strtok is causing segmentation fault
    By yougene in forum C Programming
    Replies: 11
    Last Post: 03-08-2008, 10:32 AM
  3. trying to use strtok() function to parse CL
    By ohaqqi in forum C Programming
    Replies: 15
    Last Post: 07-01-2007, 09:38 PM
  4. Help debugging my program
    By shoobsie in forum C Programming
    Replies: 4
    Last Post: 07-05-2005, 07:14 AM
  5. Trouble with strtok()
    By BianConiglio in forum C Programming
    Replies: 2
    Last Post: 05-08-2004, 06:56 PM