Inumerer la fonction strncmp
je veux creer la fonction strncmp est_ce quelqu un peut m'aider
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include<stdio.h>
int strncmp2(const char *s1, const char *s2, int n) {
int i;
for(i = 0; i <= n; i++) {
while((*s1 != '\0') && (*s2 != '\0') && (*s1++ == *s2++)) {
}
continue;
}
return *s1 - *s2;
}
int main(void) {
int n;
n = strncmp2("baller", "aller", 4);
printf("% d\n", n);
n = strncmp2("foo", "foox", 3);
printf("% d\n", n);
n = strncmp2("fool", "foobL", 4);
printf("% d\n", n);
return 0;
} |