почему я получаю предупреждение: сравнение между указателем и целым числом - PullRequest
0 голосов
/ 08 апреля 2020

Я получаю сообщение с предупреждением:

сравнение между указателем и целым числом

char * replaceWord(const char * str, const char * oldWord, const char * newWord)
{
    char * resultString;
    int i, count = 0;
    int newWordLength = strlen(newWord);
    int oldWordLength = strlen(oldWord);
    //count the no of occurance of word in string in a file
    for (i = 0; str[i] !='\0'; i++)
    {
        if (strstr(str[i], oldWord) == str[i])//i m getting warning here
        {
            count++;

            i = i + oldWordLength - 1;
        }

    }

    // Making a new string to fit in the replaced words
    resultString = (char *)malloc(i + count * (newWordLength - oldWordLength) + 1);

    i = 0;
    while (*str!='\0')
    {
        // Compare the substring with result
        if(strstr(str, oldWord) == str)//here i used same syantax its working but not above 
        {
            strcpy(&resultString[i], newWord);
            i += newWordLength;
            str += oldWordLength;
        }
        else{
            resultString[i] = *str;
            i += 1;
            str +=1;
        }
    }
    resultString[i] = '\0';
    return resultString;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...