#include <stdio.h>
#include <string.h>
int scomp(char* x, char* y);
int main(void)
{
printf("gimme a string: ");
char* str1;
scanf("%s",str1);
printf("gimme another string: ");
char* str2;
scanf("%s",str2);
printf("comparing them......\n__________\n");
if(scomp(str1,str2) == 0)
{
printf("yup, they are the same\n");
}else if(scomp(str1,str2)== 1){
printf("They are different buddy..\n");
}
return 0;
}
int scomp(char* x, char* y)
{
int n=0;
while(x[n] != '\0')
{
if(x[n] == y[n])
{
n++;
}else{
return 1;
}
}
return 0;
}
It gives me segmentation fault 11, there must be something wrong with the function I wrote in the last part which is supposed to compare strings. what's the problem?