Thread: pls help me out ERROR!!

  1. #1
    modace
    Guest

    Question pls help me out ERROR!!

    void GetSymbol ()
    {
    char *s, *tp;
    char sep[2] ;
    sep[0] = ' '; sep[1] = '\0';

    gets(s);
    tp = strtok (s,sep);
    while (tp != NULL)
    {
    printf("%s\n",tp);
    tp = strtok (NULL,sep);
    }

    }



    int main()
    {
    GetSymbol();
    return 0;
    }

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You didn't assign any memory to *s
    gets() is old an bad, dont use it (use fgets() )
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >char *s, *tp;

    s is just a pointer. Allocate some space for it with malloc() or do this instead:

    char s[100], *tp;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM