Is there a function like strncmp(str1, str2, n) (im not sure if parameters go in that order) but "n" would be the number where the strings would start to be compared not where they would end comparing?
Is there a function like strncmp(str1, str2, n) (im not sure if parameters go in that order) but "n" would be the number where the strings would start to be compared not where they would end comparing?
assuming both strings are at least n characters long:
strcmp(str1+n, str2+n);
alex
yes your right there is a strncmp. Its prototyped like this :-
int strncmp(const char* s1,const char* s2,size_t num);
you will find it in string.h just like the other string functions.It will compare up to num chars from the two null-terminated strings. return values are as for strcmp.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
I have a similar question. If I find a string using strstr(str1, sentence) how would I be able to get the position number of where that word begins?
eg. strstr("Person walking.", "walking"); /* walking begins at position 7 or 8 depending if counting starts from 0 */
Then I would assign i=/* the return value of position of that special function */