Skip to content

Commit 5293edc

Browse files
authored
Update hello.c
Fix mixed spaces/tabs indentation
1 parent cf021f6 commit 5293edc

File tree

1 file changed

+22
-38
lines changed
  • 00_Alternate_Languages/45_Hello/ANSI_C

1 file changed

+22
-38
lines changed

00_Alternate_Languages/45_Hello/ANSI_C/hello.c

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
#include <stdio.h>
22
#include <string.h>
3-
43
#define TRUE 1
54
#define FALSE 0
65
#define MAX_INPUT_LENGTH 80
7-
86
void tab(int number_of_spaces);
97
void get_input(char *input_buffer);
108
int strings_match(char *string1, char *string2);
11-
129
int main() {
1310
int done = FALSE;
1411
int paid = FALSE;
1512
int maybe_more, sure;
16-
1713
char name[MAX_INPUT_LENGTH];
1814
char reply[MAX_INPUT_LENGTH];
19-
2015
tab(33);
2116
printf("HELLO\n");
2217
tab(15);
@@ -26,26 +21,22 @@ int main() {
2621
printf("\n\nWHAT'S YOUR NAME ");
2722
get_input(name);
2823
printf("\nHI THERE, %s, ARE YOU ENJOYING YOURSELF HERE ", name);
29-
3024
get_input(reply);
3125
while (!strings_match(reply, "YES") && !strings_match(reply, "NO")) {
3226
printf("%s, I DON'T UNDERSTAND YOUR ANSWER OF '%s'.\n", name, reply);
3327
printf("PLEASE ANSWER 'YES' OR 'NO'. DO YOU LIKE IT HERE ");
3428
get_input(reply);
3529
}
36-
3730
if (strings_match(reply, "YES")) {
3831
printf("I'M GLAD TO HEAR THAT, %s.\n", name);
3932
}
4033
else {
4134
printf("OH, I'M SORRY TO HEAR THAT, %s. MAYBE WE CAN "
4235
"BRIGHTEN UP YOUR VISIT A BIT.\n", name);
4336
}
44-
4537
printf("\nSAY, %s, I CAN SOLVE ALL KINDS OF PROBLEMS EXCEPT "
4638
"THOSE DEALING WITH GREECE. WHAT KIND OF PROBLEMS DO "
4739
"YOU HAVE (ANSWER SEX, HEALTH, MONEY, OR JOB) ", name);
48-
4940
while (!done) {
5041
get_input(reply);
5142

@@ -55,7 +46,6 @@ int main() {
5546
"REALLY BEAT ON MY KEYBOARD. MY ADVICE TO YOU, %s, IS TO "
5647
"OPEN A RETAIL COMPUTER STORE. IT'S GREAT FUN.\n\n", name, name);
5748
}
58-
5949
else if (strings_match(reply, "MONEY")) {
6050
printf("SORRY, %s, I'M BROKE TOO. WHY DON'T YOU SELL "
6151
"ENCYCLOPEADIAS OR MARRY SOMEONE RICH OR STOP EATING "
@@ -74,23 +64,23 @@ int main() {
7464

7565
sure = FALSE;
7666
while (!sure) {
77-
get_input(reply);
78-
if (strings_match(reply, "TOO MUCH")) {
79-
printf("YOU CALL THAT A PROBLEM?!! I SHOULD HAVE SUCH PROBLEMS!\n");
80-
printf("IF IT BOTHERS YOU, %s, TAKE A COLD SHOWER.\n\n", name);
81-
sure = TRUE;
82-
}
83-
else if (strings_match(reply, "TOO LITTLE")) {
84-
printf("WHY ARE YOU HERE IN SUFFERN, %s? YOU SHOULD BE "
85-
"IN TOKYO OR NEW YORK OR AMSTERDAM OR SOMEPLACE WITH SOME "
86-
"REAL ACTION.\n\n", name);
87-
sure = TRUE;
88-
}
89-
else {
90-
printf("DON'T GET ALL SHOOK, %s, JUST ANSWER THE QUESTION "
91-
"WITH 'TOO MUCH' OR 'TOO LITTLE'. WHICH IS IT ", name);
92-
}
93-
}
67+
get_input(reply);
68+
if (strings_match(reply, "TOO MUCH")) {
69+
printf("YOU CALL THAT A PROBLEM?!! I SHOULD HAVE SUCH PROBLEMS!\n");
70+
printf("IF IT BOTHERS YOU, %s, TAKE A COLD SHOWER.\n\n", name);
71+
sure = TRUE;
72+
}
73+
else if (strings_match(reply, "TOO LITTLE")) {
74+
printf("WHY ARE YOU HERE IN SUFFERN, %s? YOU SHOULD BE "
75+
"IN TOKYO OR NEW YORK OR AMSTERDAM OR SOMEPLACE WITH SOME "
76+
"REAL ACTION.\n\n", name);
77+
sure = TRUE;
78+
}
79+
else {
80+
printf("DON'T GET ALL SHOOK, %s, JUST ANSWER THE QUESTION "
81+
"WITH 'TOO MUCH' OR 'TOO LITTLE'. WHICH IS IT ", name);
82+
}
83+
}
9484
}
9585

9686
else { // not one of the prescribed categories
@@ -115,7 +105,6 @@ int main() {
115105
}
116106
} // no further questions
117107
} // end of 'not done' loop
118-
119108
printf("\nTHAT WILL BE $5.00 FOR THE ADVICE, %s.\n", name);
120109
printf("PLEASE LEAVE THE MONEY ON THE TERMINAL.\n");
121110
// pause a few seconds
@@ -142,23 +131,18 @@ int main() {
142131
}
143132
}
144133
}
145-
146-
147134
void tab(int number_of_spaces) {
148135
for (int i=0; i < number_of_spaces; i++)
149136
putchar(' ');
150137
}
151-
152-
153138
void get_input(char *input_buffer) {
154139
fgets(input_buffer, MAX_INPUT_LENGTH - 1, stdin);
155140
input_buffer[strcspn(input_buffer, "\n")] = '\0'; // trim the trailing line break
156141
}
157-
158-
159142
int strings_match(char *string1, char *string2) {
160-
if (strncmp(string1, string2, MAX_INPUT_LENGTH - 1) != 0)
161-
return FALSE;
162-
else // strings match, at least within maximum input line length
163-
return TRUE;
143+
if (strncasecmp(string1, string2, MAX_INPUT_LENGTH - 1) != 0)
144+
return FALSE;
145+
else // strings match, at least within maximum input line length
146+
return TRUE;
164147
}
148+

0 commit comments

Comments
 (0)