C examples for String:String Function
Copy string by length, like strncmp
#include <stdio.h> int _strncmp(char *s, char *t, int n); int main(void) { char *s, *t;//from w w w . j a v a 2 s . c o m s = "testabc"; t = "testddc"; printf("%s cmp %s: %d\n", s, t, _strncmp(s, t, 5)); return 0; } int _strncmp(char *s, char *t, int n) { for (; n-- > 0 && *s == *t; ++s, ++t){ if (*s == '\0' || n == 0) return 0; } return *s - *t; }