Update hello.c

Fix mixed spaces/tabs indentation
This commit is contained in:
nrezmerski
2023-10-24 15:08:24 -05:00
committed by GitHub
parent cf021f6c7b
commit 5293edcd89

View File

@@ -1,22 +1,17 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#define TRUE 1 #define TRUE 1
#define FALSE 0 #define FALSE 0
#define MAX_INPUT_LENGTH 80 #define MAX_INPUT_LENGTH 80
void tab(int number_of_spaces); void tab(int number_of_spaces);
void get_input(char *input_buffer); void get_input(char *input_buffer);
int strings_match(char *string1, char *string2); int strings_match(char *string1, char *string2);
int main() { int main() {
int done = FALSE; int done = FALSE;
int paid = FALSE; int paid = FALSE;
int maybe_more, sure; int maybe_more, sure;
char name[MAX_INPUT_LENGTH]; char name[MAX_INPUT_LENGTH];
char reply[MAX_INPUT_LENGTH]; char reply[MAX_INPUT_LENGTH];
tab(33); tab(33);
printf("HELLO\n"); printf("HELLO\n");
tab(15); tab(15);
@@ -26,14 +21,12 @@ int main() {
printf("\n\nWHAT'S YOUR NAME "); printf("\n\nWHAT'S YOUR NAME ");
get_input(name); get_input(name);
printf("\nHI THERE, %s, ARE YOU ENJOYING YOURSELF HERE ", name); printf("\nHI THERE, %s, ARE YOU ENJOYING YOURSELF HERE ", name);
get_input(reply); get_input(reply);
while (!strings_match(reply, "YES") && !strings_match(reply, "NO")) { while (!strings_match(reply, "YES") && !strings_match(reply, "NO")) {
printf("%s, I DON'T UNDERSTAND YOUR ANSWER OF '%s'.\n", name, reply); printf("%s, I DON'T UNDERSTAND YOUR ANSWER OF '%s'.\n", name, reply);
printf("PLEASE ANSWER 'YES' OR 'NO'. DO YOU LIKE IT HERE "); printf("PLEASE ANSWER 'YES' OR 'NO'. DO YOU LIKE IT HERE ");
get_input(reply); get_input(reply);
} }
if (strings_match(reply, "YES")) { if (strings_match(reply, "YES")) {
printf("I'M GLAD TO HEAR THAT, %s.\n", name); printf("I'M GLAD TO HEAR THAT, %s.\n", name);
} }
@@ -41,11 +34,9 @@ int main() {
printf("OH, I'M SORRY TO HEAR THAT, %s. MAYBE WE CAN " printf("OH, I'M SORRY TO HEAR THAT, %s. MAYBE WE CAN "
"BRIGHTEN UP YOUR VISIT A BIT.\n", name); "BRIGHTEN UP YOUR VISIT A BIT.\n", name);
} }
printf("\nSAY, %s, I CAN SOLVE ALL KINDS OF PROBLEMS EXCEPT " printf("\nSAY, %s, I CAN SOLVE ALL KINDS OF PROBLEMS EXCEPT "
"THOSE DEALING WITH GREECE. WHAT KIND OF PROBLEMS DO " "THOSE DEALING WITH GREECE. WHAT KIND OF PROBLEMS DO "
"YOU HAVE (ANSWER SEX, HEALTH, MONEY, OR JOB) ", name); "YOU HAVE (ANSWER SEX, HEALTH, MONEY, OR JOB) ", name);
while (!done) { while (!done) {
get_input(reply); get_input(reply);
@@ -55,7 +46,6 @@ int main() {
"REALLY BEAT ON MY KEYBOARD. MY ADVICE TO YOU, %s, IS TO " "REALLY BEAT ON MY KEYBOARD. MY ADVICE TO YOU, %s, IS TO "
"OPEN A RETAIL COMPUTER STORE. IT'S GREAT FUN.\n\n", name, name); "OPEN A RETAIL COMPUTER STORE. IT'S GREAT FUN.\n\n", name, name);
} }
else if (strings_match(reply, "MONEY")) { else if (strings_match(reply, "MONEY")) {
printf("SORRY, %s, I'M BROKE TOO. WHY DON'T YOU SELL " printf("SORRY, %s, I'M BROKE TOO. WHY DON'T YOU SELL "
"ENCYCLOPEADIAS OR MARRY SOMEONE RICH OR STOP EATING " "ENCYCLOPEADIAS OR MARRY SOMEONE RICH OR STOP EATING "
@@ -74,23 +64,23 @@ int main() {
sure = FALSE; sure = FALSE;
while (!sure) { while (!sure) {
get_input(reply); get_input(reply);
if (strings_match(reply, "TOO MUCH")) { if (strings_match(reply, "TOO MUCH")) {
printf("YOU CALL THAT A PROBLEM?!! I SHOULD HAVE SUCH PROBLEMS!\n"); printf("YOU CALL THAT A PROBLEM?!! I SHOULD HAVE SUCH PROBLEMS!\n");
printf("IF IT BOTHERS YOU, %s, TAKE A COLD SHOWER.\n\n", name); printf("IF IT BOTHERS YOU, %s, TAKE A COLD SHOWER.\n\n", name);
sure = TRUE; sure = TRUE;
} }
else if (strings_match(reply, "TOO LITTLE")) { else if (strings_match(reply, "TOO LITTLE")) {
printf("WHY ARE YOU HERE IN SUFFERN, %s? YOU SHOULD BE " printf("WHY ARE YOU HERE IN SUFFERN, %s? YOU SHOULD BE "
"IN TOKYO OR NEW YORK OR AMSTERDAM OR SOMEPLACE WITH SOME " "IN TOKYO OR NEW YORK OR AMSTERDAM OR SOMEPLACE WITH SOME "
"REAL ACTION.\n\n", name); "REAL ACTION.\n\n", name);
sure = TRUE; sure = TRUE;
} }
else { else {
printf("DON'T GET ALL SHOOK, %s, JUST ANSWER THE QUESTION " printf("DON'T GET ALL SHOOK, %s, JUST ANSWER THE QUESTION "
"WITH 'TOO MUCH' OR 'TOO LITTLE'. WHICH IS IT ", name); "WITH 'TOO MUCH' OR 'TOO LITTLE'. WHICH IS IT ", name);
} }
} }
} }
else { // not one of the prescribed categories else { // not one of the prescribed categories
@@ -115,7 +105,6 @@ int main() {
} }
} // no further questions } // no further questions
} // end of 'not done' loop } // end of 'not done' loop
printf("\nTHAT WILL BE $5.00 FOR THE ADVICE, %s.\n", name); printf("\nTHAT WILL BE $5.00 FOR THE ADVICE, %s.\n", name);
printf("PLEASE LEAVE THE MONEY ON THE TERMINAL.\n"); printf("PLEASE LEAVE THE MONEY ON THE TERMINAL.\n");
// pause a few seconds // pause a few seconds
@@ -142,23 +131,18 @@ int main() {
} }
} }
} }
void tab(int number_of_spaces) { void tab(int number_of_spaces) {
for (int i=0; i < number_of_spaces; i++) for (int i=0; i < number_of_spaces; i++)
putchar(' '); putchar(' ');
} }
void get_input(char *input_buffer) { void get_input(char *input_buffer) {
fgets(input_buffer, MAX_INPUT_LENGTH - 1, stdin); fgets(input_buffer, MAX_INPUT_LENGTH - 1, stdin);
input_buffer[strcspn(input_buffer, "\n")] = '\0'; // trim the trailing line break input_buffer[strcspn(input_buffer, "\n")] = '\0'; // trim the trailing line break
} }
int strings_match(char *string1, char *string2) { int strings_match(char *string1, char *string2) {
if (strncmp(string1, string2, MAX_INPUT_LENGTH - 1) != 0) if (strncasecmp(string1, string2, MAX_INPUT_LENGTH - 1) != 0)
return FALSE; return FALSE;
else // strings match, at least within maximum input line length else // strings match, at least within maximum input line length
return TRUE; return TRUE;
} }