Hi Im new to coding in C and I can't seem to find the problem which causes a segfault after the while loop starts.
int main() {
char option;
char nickname;
printf("Welcome to our chat program. Please select mode (Send,Nickname,Exit): ");
while (gets(option)) {
if(!strncmp(option, "Exit", 4)) {
break;
}
if(!strncmp(option, "Nickname", 8)){
set_nickname(nickname);
}
if(!strncmp(option, "Send", 4)){
if(!nickname){
nickname = "Anonymous";
printf("Your nickname was set to Anonymous!");
}
send_message(nickname);
}
}
-W -Wallby example. Then you'll see your errors.optionandnicknamewhilst you're comparing them with multiple character strings. That might be the problem.gcc -Wall -Wextra -g). Use the debugger (gdb) & valgrind. BTWgetsis obsolete and should never be used. Usefgets,getline,readline