I've just started to learn c and i wanted to try the strcmp function, but it somehow always gives me the result "1", if I run it. Doesn't matter what strings I type in. Since the first string is shorter than the second, i expected "-1" as a result.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char array1[]="na";
char array2[]="kskkjnkjnknjd";
int i;
i= strcmp(array1,array2);
printf(" %d", i);
return 0;
}
I also already tried to get rid of the i variable and just write "printf(" %d", strcmp(array1, array2)); and replacing the %d by a %u, but also not working. I've already searched the web and tried figuring it out for myself, probably just a simple mistake, would be glad if anyone could help. :)