Does it const char *smean that "s is a pointer pointing to a constant char", then why does it give me this warning? I am not trying to change the values.
In the first warning function return discards 'const' qualifiers from pointer target type.
and in the second - assignment discards 'const' qualifiers from pointer target type.
I tried to create library functions that are defined in string.h, and also tell me how to fix it.
char *my_strchr( const char *s, int c )
{
for(;*s!='\0';s++)
if(*s==c)
return s;
return 0;
}
char *my_strpbrk( const char *s1, const char *s2 )
{
char *s2ptr;
for(;*s1!='\0';s1++)
for(s2ptr=s2;*s2ptr!='\0';s2ptr++)
if(*s1==*s2ptr)
return s2ptr;
return 0;
}
Umair source
share