I’m programming in C (Linux OS). I need to use rindex for finding last occurence of a char specified as function argument.
char * rindex (const char *string, char c);
It works fine though I get warnings:
conflicting types for built-in function ‘rindex’ [enabled by default]
But if I include a string.h header. It gives error,
conflicting types for ‘rindex’
because there rindex is defined as,
char * rindex (const char *string, int c);
But I need to use it as char and also use the string.h for string operations. Is there any possibility? Kindly guide me.
In 7th Edition UNIX™, there were two functions
index()andrindex()that are respectively equivalent to the standard C functionsstrchr()andstrrchr(), give or takeconst(which didn’t exist when those functions were defined, any more than prototypes existed; there wasn’t even C with Classes back then).You’re running foul of the backwards-compatible declarations of the function
rindex(). The namesindex()andrindex()are archaic, but you can’t use them blithely in your own code. Choose a different function name.