Jung
Jung

Reputation: 81

C - strsep() function with int error, return value is char*

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.

Upvotes: 0

Views: 1094

Answers (1)

Peter
Peter

Reputation: 36607

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().

Upvotes: 3

Related Questions