comparing 2 strings with pointer
Hello all,
I am trying to make a program that compares two strings, but I got stuck here ;)
I am a newbie in using pointer, can anyone help?
here is the source code :
Code:
#include <stdio.h>
int str_equal(const char *s1, const char *s2){
while(*s1 != '\0' && *s2 != '\0'){
if(*s1 != *s2){return 0;}
else{*s1++;*s2++;}
}
return 1;
}
int main(void){
char p, q;
printf("Input a string : ");
scanf("%s",&p);
printf("Input another string : ");
scanf("%s",&q);
if(str_equal(&p, &q)){
printf("The strings are the same.\n");
}else{
printf("The strings are not the same.\n");
}
return 0;
}
thanks in advance.