簡體   English   中英

C-strsep()函數出現int錯誤,返回值為char *

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

我在C代碼中使用了strsep(),但是遇到了這個錯誤。

在此處輸入圖片說明

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++;
    }
}

這是我的代碼,我使用strsep()這樣。 我不知道錯誤說int。 我認為strsep()返回char *。

您正在使用的實現未在<string.h>聲明strsep()

后果是;

  1. 編譯器假定strsep()返回int (因此出現第一個警告)
  2. 鏈接器( ld )在鏈接包含的庫中找不到名為strsep()的函數(因此ld無法解決strsep()錯誤)。

發生這種情況的原因是strsep()不屬於標准C庫。 您要么需要獲取一個包含它的庫,要么“滾動自己的”版本的strsep()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM