1

When I compile this code:

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

I got this error:

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

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

and there is an arrow point to the equal sign that is between pch and strcasestr

1
  • 1
    Do you also get warnings when you compile with -Wall? strcasestr isn't a standard function and may not be defined in <string.h>, so that your compiler assumes that it returns an int. That would explain why ther isn't an error for the same code with strstr. Commented Feb 4, 2016 at 18:37

2 Answers 2

2

From the man page:

   #define _GNU_SOURCE

   #include <string.h>

   char *strcasestr(const char *haystack, const char *needle);

You need to add #define _GNU_SOURCE before you #include <string.h> (and #include <stdio.h> as well) in order for the function declaration to be visible.

Sign up to request clarification or add additional context in comments.

Comments

0

while ( (pch = strcasestr(str,patt)) != NULL) strcasestr is a nonstandard extension, so you must add #define _GNU_SOURCE on the first line of your file, or compile with -D_GNU_SOURCE.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.