1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
int main() {
const char* str1 = "String 1";
const char* str2 = "String 2";
char str3[64] = "String 3 ";
char str4[64] = "String 4";
int a, b, i, j = i = b = a = 0;
printf("Comparing str1 & str2\n");
a = mstrcmp(str1, str2); /* This should = 1 ('2' - '1' == 1) */
printf("Comparing first 7 chars of str1 & str2\n");
b = mstrncmp(str1, str2, 7); /* This should = 0 */
printf("Getting lengths of str1, str2\n");
i = mstrlen(str1);
j = mstrlen(str2);
printf("Concatenating str3 & str4\n");
mstrcat(str3, str4);
/* Works fine up to here */
printf("Doing strcopy on str4");
strncopy(str4, "This is ", 8);
printf("\nDone.\nResults:"
"\n\t%d\n\t%d\n\t%d\n\t%d"
"\n\t%s\n\t%s\n",
a, b, i, j, str3, str4
);
fflush(stdout);
return 0;
}
|
Comparing str1 & str2
Comparing first 7 chars of str1 & str2
Getting lengths of str1, str2
Concatenating str3 & str4
Doing strncopy on str4
Done.
Results:
1
0
8
8
String 3 String 4
This is |