Start like this
Code:
int myStrncmp ( const char *a, const char *b, size_t len ) {
return strncmp( a, b, len );
}
size_t myStrlen ( const char *a ) {
return strlen( a );
}
char *myStrstr ( const char *haystack, const char *needle ) {
return strstr( haystack, needle );
}
Then refine one of the functions to say
Code:
char *myStrstr ( const char *haystack, const char *needle ) {
size_t h_len = myStrlen( haystack );
size_t n_len = myStrlen( needle );
size_t i;
for ( i = 0 ; i < (h_len-n_len) ; i++ ) {
if ( myStrncmp( &haystack[i], needle, n_len ) == 0 ) {
return &haystack[i];
}
}
return NULL;
}
The point is, you start with something which works, which means when you write your own version and it stops working, you have some idea of where the problem is.
> Well, we've been told that for the exams we wont be allowed to use any library fuctions
That's only in the answer you hand in. Nothing wrong with using them to get you moving forwards.