我编写了一个用于在文本中查找特定单词的函数,但我有一个问题,我使用 strcmp_function 获取 const char 参数,而 a[] 不是 cons char。我如何在这个程序中使用这个功能?(w 表示单词)
int comparision(const char sentence[ ],char *w)
{
int i, length=0, c=0, l=0;
int j,count=0;
char a[20]={'0'};
length= strlen(sentence);
l= strlen(w);
for (i=0; i<length; i++)
{
if (sentence[i] == ' '||sentence[i] == '\t'||sentence[i] == '\n')
{
for(j=0;j<l;j++)
a[j]=sentence[j+i+1];
a[j+1]='\0';
if( strcmp(a,w)==0)
count++;
}}
return count;
}