asked 23.0k views
5 votes
In c language Write an if-else statement that prints "Goodbye" if userString is "Quit", else prints "Hello". End with newline.

asked
User Einius
by
8.3k points

1 Answer

6 votes

Answer:

#include <stdio.h>

#include <string.h>

int main() {

char userString[20]; // Assuming the maximum length of user input is 20 characters

printf("Enter a string: ");

fgets(userString, sizeof(userString), stdin);

userString[strcspn(userString, "\\")] = '\0'; // Remove the newline character

if (strcmp(userString, "Quit") == 0) {

printf("Goodbye\\");

} else {

printf("Hello\\");

}

return 0;

}

answered
User Xplora
by
8.2k points