why is strcmp returning 1 in this case?? doesn't the contents of "somestring" match "test".
I've tried removing the trailing \n's that fgets puts in but still the same. I input test when prompted.
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
{
char somestring[100];
printf("Please enter a string\n");
fgets(somestring, 100, stdin);
//the following will rebuild the string to get rid of any new lines so we can compare
//it with "test".
int i;
for (i=0; i < strlen(somestring)-1; i++)
{
if (somestring[i] != '\n'){
somestring[i] = somestring[i];
}
}
printf("\n%d", strcmp(somestring, "test"));
return 0;
}