得到错误“对"strsep"的未定义引用".与Clang和MinGW [英] Getting the error "undefined reference to 'strsep'" with Clang and MinGW

查看:145
本文介绍了得到错误“对"strsep"的未定义引用".与Clang和MinGW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是相关代码:

#define _GNU_SOURCE
#define BUFFER_SIZE 1024

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
    while (1) {
        char* buffer;
        size_t size = 32;
        size_t line;
        line = getline(&buffer,&size,stdin);
        printf("%s\n",buffer);

        int commandList[line];
        int count = 0;
        while (strsep(buffer," ")) {
            commandList[count] = strsep(buffer," ");
            count++;
        }
    }
}

我正在将代码块与minGW和Clang一起使用.

I am using Code Blocks with minGW and Clang.

我知道目前我的某些代码无法实现预期的功能,但是我很确定它至少应该编译.我也收到警告:函数'strsep'的隐式声明".

I know some of my code does not do what it is supposed to at the moment, but I am pretty sure it should at least compile. I am also getting a warning: "implicit declaration of function 'strsep'".

推荐答案

strsep对自己实现很简单

strsep is trivial to implement yourself

#include <string.h>

char *strsep(char **stringp, const char *delim) {
    char *rv = *stringp;
    if (rv) {
        *stringp += strcspn(*stringp, delim);
        if (**stringp)
            *(*stringp)++ = '\0';
        else
            *stringp = 0; }
    return rv;
}

这篇关于得到错误“对"strsep"的未定义引用".与Clang和MinGW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆