is there any function out there in C to know the position of a string in another string? i mean, like a strpos() function from PHP? if any code out there is available, id really appreciate that!
is there any function out there in C to know the position of a string in another string? i mean, like a strpos() function from PHP? if any code out there is available, id really appreciate that!
The function is strstr().
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
i mean, that function should return the position (probably an array index) of the string inside the bigger string?
so something like this:
--Code:int strpos(char *haystack, char *needle) { char *p = strstr(haystack, needle); if (p) return p - haystack; return -1; // Not found = -1. }
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.