0

I used strsep() in C code, but I got this error.

enter image description here

void    get_token()
{ 
    char    *token;
    char    *stringp;
    int n = 1;

    stringp = buf;

    while( stringp != NULL )
    {
            token = strsep(&stringp, "\t\n");
            switch(n) {
            case 1 : strcpy(label, token);
            case 2 : strcpy(opcode, token);
            case 3 : strcpy(operand, token);
            } n++;
    }
}

This is my code and I using strsep() like this. I don't know the error said int. strsep() return char* I think.

MD XF
  • 7,860
  • 7
  • 40
  • 71
Jung
  • 81
  • 10

1 Answers1

3

You are using an implementation that does not declare strsep() in <string.h>.

Consequences are;

  1. the compiler assumes strsep() returns int (hence the first warning)
  2. the linker (ld) does not find a function named strsep() in libraries included in the link (hence error about strsep() being unresolved by ld).

The reason this occurs is that strsep() is not part of the standard C library. You either need to obtain a library that contains it, or "roll your own" version of strsep().

Peter
  • 35,646
  • 4
  • 32
  • 74
  • It doesn't work even I declared So I made strsep() function. – Jung Dec 20 '15 at 05:33
  • 1
    Note: `strsep()` is _not_ a POSIX function. It was first provided on BSD, AFAIK, and may now be available on some other platforms, such as Linux. – Jonathan Leffler Dec 20 '15 at 08:34
  • 1
    To make `strsep()` available through `strings.h` on Linux using GCC you want to `#define` `_BSD_SOURCE`. For you reference the Linux man-page here: http://man7.org/linux/man-pages/man3/strsep.3.html – alk Dec 20 '15 at 10:01