簡體   English   中英

賦值使指針從整數開始,默認情況下未啟用強制轉換

[英]assignment makes pointer from integer without a cast enabled by default

當我編譯這段代碼時:

void rep_and_print(char * str, char * patt, int l, int i)
{
    char * pch; // pointer to occurence
    char * s;
    s = str; // save original pointer
    if (i == 0)
    {
        while ( (pch = strstr(str,patt)) != NULL)
        {
            // FOUND
            memset (pch,'*',l); // Set asterisk
            str = pch + l; // move pointer to the end of asterisks to found new  occurences
        }
    }
    else
    {
        while ( (pch = strcasestr(str,patt)) != NULL)
        {
            // FOUND
            memset (pch,'*',l); // Set asterisk
            str = pch + l; // move pointer to the end of asterisks to found new occurences
        }
    }
    printf ("%s",s);
}

我收到此錯誤:

警告:賦值使指針從整數開始而沒有強制轉換[默認啟用]

while ( (pch = strcasestr(str,patt)) != NULL)

並且在pchstrcasestr之間有一個指向等號的箭頭

從手冊頁:

  #define _GNU_SOURCE #include <string.h> char *strcasestr(const char *haystack, const char *needle); 

為了使函數聲明可見,您需要在#include <string.h> (以及#include <stdio.h> )之前添加#define _GNU_SOURCE

while((pch = strcasestr(str,patt))!= NULL)strcasestr是非標准擴展,因此您必須在文件的第一行添加#define _GNU_SOURCE,或使用-D_GNU_SOURCE進行編譯。

暫無
暫無

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

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