I recently wrote a program that is supposed to prompt a user for two strings, compare those two strings, and then display to the user whether they are the same or different. My program compiles okay but when I run it, after it prompts me for the strings, it comes up with "segmentation fault: 11". I'm not sure what I am doing wrong or how to fix it in this case.
// Compares two strings
#include <stdio.h>
#include <string.h>
int main(void) {
char *s;
char *t;
int ret;
// prompt user for two strings
printf("string a: ");
scanf("%s", s);
printf("string b: ");
scanf("%s", t);
// compare strings
ret = strcmp(s, t);
if(ret == 0) {
printf("Same\n");
}
else {
printf("Different\n");
}
return 0;
}