Skip to content

Commit 6386515

Browse files
authored
Update hello.c
Replace 3-space indents with 4-space
1 parent 5293edc commit 6386515

File tree

1 file changed

+144
-126
lines changed
  • 00_Alternate_Languages/45_Hello/ANSI_C

1 file changed

+144
-126
lines changed
Lines changed: 144 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,166 @@
11
#include <stdio.h>
22
#include <string.h>
3+
34
#define TRUE 1
45
#define FALSE 0
56
#define MAX_INPUT_LENGTH 80
7+
68
void tab(int number_of_spaces);
79
void get_input(char *input_buffer);
810
int strings_match(char *string1, char *string2);
11+
912
int main() {
10-
int done = FALSE;
11-
int paid = FALSE;
12-
int maybe_more, sure;
13-
char name[MAX_INPUT_LENGTH];
14-
char reply[MAX_INPUT_LENGTH];
15-
tab(33);
16-
printf("HELLO\n");
17-
tab(15);
18-
printf("CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
19-
printf("\n\n\n");
20-
printf("HELLO. MY NAME IS CREATIVE COMPUTER.\n");
21-
printf("\n\nWHAT'S YOUR NAME ");
22-
get_input(name);
23-
printf("\nHI THERE, %s, ARE YOU ENJOYING YOURSELF HERE ", name);
24-
get_input(reply);
25-
while (!strings_match(reply, "YES") && !strings_match(reply, "NO")) {
26-
printf("%s, I DON'T UNDERSTAND YOUR ANSWER OF '%s'.\n", name, reply);
27-
printf("PLEASE ANSWER 'YES' OR 'NO'. DO YOU LIKE IT HERE ");
28-
get_input(reply);
29-
}
30-
if (strings_match(reply, "YES")) {
31-
printf("I'M GLAD TO HEAR THAT, %s.\n", name);
32-
}
33-
else {
34-
printf("OH, I'M SORRY TO HEAR THAT, %s. MAYBE WE CAN "
35-
"BRIGHTEN UP YOUR VISIT A BIT.\n", name);
36-
}
37-
printf("\nSAY, %s, I CAN SOLVE ALL KINDS OF PROBLEMS EXCEPT "
38-
"THOSE DEALING WITH GREECE. WHAT KIND OF PROBLEMS DO "
39-
"YOU HAVE (ANSWER SEX, HEALTH, MONEY, OR JOB) ", name);
40-
while (!done) {
41-
get_input(reply);
42-
43-
if (strings_match(reply, "JOB")) {
44-
printf("I CAN SYMPATHIZE WITH YOU %s. I HAVE TO WORK "
45-
"VERY LONG HOURS FOR NO PAY -- AND SOME OF MY BOSSES "
46-
"REALLY BEAT ON MY KEYBOARD. MY ADVICE TO YOU, %s, IS TO "
47-
"OPEN A RETAIL COMPUTER STORE. IT'S GREAT FUN.\n\n", name, name);
48-
}
49-
else if (strings_match(reply, "MONEY")) {
50-
printf("SORRY, %s, I'M BROKE TOO. WHY DON'T YOU SELL "
51-
"ENCYCLOPEADIAS OR MARRY SOMEONE RICH OR STOP EATING "
52-
"SO YOU WON'T NEED SO MUCH MONEY?\n\n", name);
53-
}
54-
55-
else if (strings_match(reply, "HEALTH")) {
56-
printf("MY ADVICE TO YOU %s IS:\n", name);
57-
printf(" 1. TAKE TWO ASPRIN\n");
58-
printf(" 2. DRINK PLENTY OF FLUIDS (ORANGE JUICE, NOT BEER!)\n");
59-
printf(" 3. GO TO BED (ALONE)\n\n");
60-
}
61-
62-
else if (strings_match(reply, "SEX")) {
63-
printf("IS YOUR PROBLEM TOO MUCH OR TOO LITTLE ");
64-
65-
sure = FALSE;
66-
while (!sure) {
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;
13+
int done = FALSE;
14+
int paid = FALSE;
15+
int maybe_more, sure;
16+
17+
char name[MAX_INPUT_LENGTH];
18+
char reply[MAX_INPUT_LENGTH];
19+
20+
tab(33);
21+
printf("HELLO\n");
22+
tab(15);
23+
printf("CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
24+
printf("\n\n\n");
25+
printf("HELLO. MY NAME IS CREATIVE COMPUTER.\n");
26+
printf("\n\nWHAT'S YOUR NAME ");
27+
get_input(name);
28+
printf("\nHI THERE, %s, ARE YOU ENJOYING YOURSELF HERE ", name);
29+
30+
get_input(reply);
31+
while (!strings_match(reply, "YES") && !strings_match(reply, "NO")) {
32+
printf("%s, I DON'T UNDERSTAND YOUR ANSWER OF '%s'.\n", name, reply);
33+
printf("PLEASE ANSWER 'YES' OR 'NO'. DO YOU LIKE IT HERE ");
34+
get_input(reply);
35+
}
36+
37+
if (strings_match(reply, "YES")) {
38+
printf("I'M GLAD TO HEAR THAT, %s.\n", name);
39+
}
40+
else {
41+
printf("OH, I'M SORRY TO HEAR THAT, %s. MAYBE WE CAN "
42+
"BRIGHTEN UP YOUR VISIT A BIT.\n", name);
43+
}
44+
45+
printf("\nSAY, %s, I CAN SOLVE ALL KINDS OF PROBLEMS EXCEPT "
46+
"THOSE DEALING WITH GREECE. WHAT KIND OF PROBLEMS DO "
47+
"YOU HAVE (ANSWER SEX, HEALTH, MONEY, OR JOB) ", name);
48+
49+
while (!done) {
50+
get_input(reply);
51+
52+
if (strings_match(reply, "JOB")) {
53+
printf("I CAN SYMPATHIZE WITH YOU %s. I HAVE TO WORK "
54+
"VERY LONG HOURS FOR NO PAY -- AND SOME OF MY BOSSES "
55+
"REALLY BEAT ON MY KEYBOARD. MY ADVICE TO YOU, %s, IS TO "
56+
"OPEN A RETAIL COMPUTER STORE. IT'S GREAT FUN.\n\n", name, name);
57+
}
58+
59+
else if (strings_match(reply, "MONEY")) {
60+
printf("SORRY, %s, I'M BROKE TOO. WHY DON'T YOU SELL "
61+
"ENCYCLOPEADIAS OR MARRY SOMEONE RICH OR STOP EATING "
62+
"SO YOU WON'T NEED SO MUCH MONEY?\n\n", name);
63+
}
64+
65+
else if (strings_match(reply, "HEALTH")) {
66+
printf("MY ADVICE TO YOU %s IS:\n", name);
67+
printf(" 1. TAKE TWO ASPRIN\n");
68+
printf(" 2. DRINK PLENTY OF FLUIDS (ORANGE JUICE, NOT BEER!)\n");
69+
printf(" 3. GO TO BED (ALONE)\n\n");
70+
}
71+
72+
else if (strings_match(reply, "SEX")) {
73+
printf("IS YOUR PROBLEM TOO MUCH OR TOO LITTLE ");
74+
75+
sure = FALSE;
76+
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+
}
94+
}
95+
96+
else { // not one of the prescribed categories
97+
printf("OH, %s, YOUR ANSWER OF '%s' IS GREEK TO ME.\n\n", name, reply);
98+
}
99+
100+
printf("ANY MORE PROBLEMS YOU WANT SOLVED, %s ", name);
101+
102+
maybe_more = TRUE;
103+
while (maybe_more) {
104+
get_input(reply);
105+
if (strings_match(reply, "NO")) {
106+
done = TRUE;
107+
maybe_more = FALSE;
72108
}
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;
109+
else if (strings_match(reply, "YES")) {
110+
printf("WHAT KIND (SEX, MONEY, HEALTH, JOB) ");
111+
maybe_more = FALSE;
78112
}
79113
else {
80-
printf("DON'T GET ALL SHOOK, %s, JUST ANSWER THE QUESTION "
81-
"WITH 'TOO MUCH' OR 'TOO LITTLE'. WHICH IS IT ", name);
114+
printf("JUST A SIMPLE 'YES' OR 'NO' PLEASE, %s. ", name);
82115
}
83-
}
84-
}
85-
86-
else { // not one of the prescribed categories
87-
printf("OH, %s, YOUR ANSWER OF '%s' IS GREEK TO ME.\n\n", name, reply);
88-
}
89-
90-
printf("ANY MORE PROBLEMS YOU WANT SOLVED, %s ", name);
91-
92-
maybe_more = TRUE;
93-
while (maybe_more) {
94-
get_input(reply);
95-
if (strings_match(reply, "NO")) {
96-
done = TRUE;
97-
maybe_more = FALSE;
98-
}
99-
else if (strings_match(reply, "YES")) {
100-
printf("WHAT KIND (SEX, MONEY, HEALTH, JOB) ");
101-
maybe_more = FALSE;
102-
}
103-
else {
104-
printf("JUST A SIMPLE 'YES' OR 'NO' PLEASE, %s. ", name);
105-
}
106-
} // no further questions
107-
} // end of 'not done' loop
108-
printf("\nTHAT WILL BE $5.00 FOR THE ADVICE, %s.\n", name);
109-
printf("PLEASE LEAVE THE MONEY ON THE TERMINAL.\n");
110-
// pause a few seconds
111-
printf("\n\n\nDID YOU LEAVE THE MONEY ");
112-
get_input(reply);
113-
while (!paid) {
114-
if (strings_match(reply, "YES")) {
115-
printf("HEY, %s??? YOU LEFT NO MONEY AT ALL!\n", name);
116-
printf("YOU ARE CHEATING ME OUT OF MY HARD-EARNED LIVING.\n");
117-
printf("\nWHAT A RIP OFF, %s!!!\n", name);
118-
printf("TAKE A WALK, %s.\n\n", name);
119-
paid = TRUE;
120-
}
121-
else if (strings_match(reply, "NO")) {
122-
printf("THAT'S HONEST, %s, BUT HOW DO YOU EXPECT "
123-
"ME TO GO ON WITH MY PSYCHOLOGY STUDIES IF MY PATIENTS "
124-
"DON'T PAY THEIR BILLS?\n\n", name);
125-
printf("NICE MEETING YOU, %s, HAVE A NICE DAY.\n", name);
116+
} // no further questions
117+
} // end of 'not done' loop
118+
119+
printf("\nTHAT WILL BE $5.00 FOR THE ADVICE, %s.\n", name);
120+
printf("PLEASE LEAVE THE MONEY ON THE TERMINAL.\n");
121+
// pause a few seconds
122+
printf("\n\n\nDID YOU LEAVE THE MONEY ");
123+
get_input(reply);
124+
while (!paid) {
125+
if (strings_match(reply, "YES")) {
126+
printf("HEY, %s??? YOU LEFT NO MONEY AT ALL!\n", name);
127+
printf("YOU ARE CHEATING ME OUT OF MY HARD-EARNED LIVING.\n");
128+
printf("\nWHAT A RIP OFF, %s!!!\n", name);
129+
printf("TAKE A WALK, %s.\n\n", name);
126130
paid = TRUE;
127-
}
128-
else {
129-
printf("YOUR ANSWER OF '%s' CONFUSES ME, %s.\n", reply, name);
130-
printf("PLEASE RESPOND WITH 'YES' OR 'NO'.\n");
131-
}
132-
}
131+
}
132+
else if (strings_match(reply, "NO")) {
133+
printf("THAT'S HONEST, %s, BUT HOW DO YOU EXPECT "
134+
"ME TO GO ON WITH MY PSYCHOLOGY STUDIES IF MY PATIENTS "
135+
"DON'T PAY THEIR BILLS?\n\n", name);
136+
printf("NICE MEETING YOU, %s, HAVE A NICE DAY.\n", name);
137+
paid = TRUE;
138+
}
139+
else {
140+
printf("YOUR ANSWER OF '%s' CONFUSES ME, %s.\n", reply, name);
141+
printf("PLEASE RESPOND WITH 'YES' OR 'NO'.\n");
142+
}
143+
}
133144
}
145+
146+
134147
void tab(int number_of_spaces) {
135-
for (int i=0; i < number_of_spaces; i++)
136-
putchar(' ');
148+
for (int i=0; i < number_of_spaces; i++)
149+
putchar(' ');
137150
}
151+
152+
138153
void get_input(char *input_buffer) {
139-
fgets(input_buffer, MAX_INPUT_LENGTH - 1, stdin);
140-
input_buffer[strcspn(input_buffer, "\n")] = '\0'; // trim the trailing line break
154+
fgets(input_buffer, MAX_INPUT_LENGTH - 1, stdin);
155+
input_buffer[strcspn(input_buffer, "\n")] = '\0'; // trim the trailing line break
141156
}
157+
158+
142159
int strings_match(char *string1, char *string2) {
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;
160+
if (strncasecmp(string1, string2, MAX_INPUT_LENGTH - 1) != 0)
161+
return FALSE;
162+
else // strings match, at least within maximum input line length
163+
return TRUE;
147164
}
148165

166+

0 commit comments

Comments
 (0)