编译此代码时:
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)
还有一个箭头指向
pch
和strcasestr
之间的等号 最佳答案
从手册页:
#define _GNU_SOURCE
#include <string.h>
char *strcasestr(const char *haystack, const char *needle);
为了使函数声明可见,需要在
#define _GNU_SOURCE
之前添加#include <string.h>
(以及#include <stdio.h>
)。关于c - 赋值使指针从整数开始,默认情况下未启用强制转换,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35208862/