String comparisons

String comparison: Detect word.

 Write an if-else statement that prints “Goodbye” if userString is “Quit”, else prints “Hello”. End with newline.
#include <stdio.h>
#include <string.h>

int main(void) {
 char userString[50];

strcpy(userString, "Quit");


 if (strcmp(userString, "Quit")==0){
 printf("Goodbye\n");
 }

 else {
 printf("Hello\n");
 }


 return 0;
}

Print two strings in alphabetical order.

Print the two strings in alphabetical order. Assume the strings are lowercase. End with newline. Sample output:

capes rabbits
#include <stdio.h>
#include <string.h>

int main(void) {
 char firstString[50];
 char secondString[50];

strcpy(firstString, "rabbits");
 strcpy(secondString, "capes");


 if (strcmp(firstString, secondString)>0){
 
printf("%s %s\n", secondString,firstString); 
}
 
 
else {
 
printf("%s %s\n",firstString, secondString); 
}


 return 0;
}