Skip to content

Commit 36a85c8

Browse files
committed
Refactor code formatting for consistency across multiple files
- Standardized indentation to 4 spaces in various C source files. - Updated function definitions and return statements for improved readability. - Ensured consistent use of braces and spacing in function bodies. - Enhanced overall code clarity and maintainability.
1 parent a2842be commit 36a85c8

File tree

109 files changed

+6554
-8357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+6554
-8357
lines changed
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <stdio.h>
22

3-
int main(void)
4-
{
5-
printf("hello, world\n");
6-
return 0;
3+
int main(void) {
4+
printf("hello, world\n");
5+
return 0;
76
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <stdio.h>
22

3-
int main(void)
4-
{
5-
printf("hello, world\c");
6-
return 0;
3+
int main(void) {
4+
printf("hello, world\c");
5+
return 0;
76
}

chapter_1/exercise_1_03/fahrenheit_celsius.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,26 @@
44
// for fahr = 0, 20, ... 300
55
// floating point version
66

7-
int main(void)
8-
{
9-
float fahr, celsius;
10-
int lower, upper, step;
7+
int main(void) {
8+
float fahr, celsius;
9+
int lower, upper, step;
1110

12-
lower = 0;
13-
upper = 300;
14-
step = 20;
11+
lower = 0;
12+
upper = 300;
13+
step = 20;
1514

16-
// Printing a heading above the table
17-
printf("Fahr\tCelsius\n");
18-
printf("---------------\n");
15+
// Printing a heading above the table
16+
printf("Fahr\tCelsius\n");
17+
printf("---------------\n");
1918

20-
fahr = lower;
21-
while (fahr <= upper)
22-
{
23-
celsius = (5.0 / 9.0) * (fahr - 32.0);
24-
printf("%3.0f\t\t%6.1f\n", fahr, celsius);
25-
fahr = fahr + step;
26-
}
19+
fahr = lower;
20+
while (fahr <= upper) {
21+
celsius = (5.0 / 9.0) * (fahr - 32.0);
22+
printf("%3.0f\t\t%6.1f\n", fahr, celsius);
23+
fahr = fahr + step;
24+
}
2725

28-
return 0;
26+
return 0;
2927
}
3028

3129
// NOTE: If all operands from an operation are integers then a integer operation

chapter_1/exercise_1_04/celsius_fahrenheit.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,23 @@
44
// for celsius = 0, 20, ... 300
55
// floating point version
66

7-
int main(void)
8-
{
9-
float celsius, fahr;
10-
int lower, upper, step;
7+
int main(void) {
8+
float celsius, fahr;
9+
int lower, upper, step;
1110

12-
lower = 0;
13-
upper = 300;
14-
step = 20;
11+
lower = 0;
12+
upper = 300;
13+
step = 20;
1514

16-
printf("Celsius\tFahr\n");
17-
printf("---------------\n");
15+
printf("Celsius\tFahr\n");
16+
printf("---------------\n");
1817

19-
celsius = lower;
20-
while (celsius <= upper)
21-
{
22-
fahr = (9.0 / 5.0) * celsius + 32.0f;
23-
printf("%3.0f\t\t%6.1f\n", celsius, fahr);
24-
celsius = celsius + step;
25-
}
18+
celsius = lower;
19+
while (celsius <= upper) {
20+
fahr = (9.0 / 5.0) * celsius + 32.0f;
21+
printf("%3.0f\t\t%6.1f\n", celsius, fahr);
22+
celsius = celsius + step;
23+
}
2624

27-
return 0;
25+
return 0;
2826
}

chapter_1/exercise_1_05/celsius_fahrenheit.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,26 @@
44
// for celsius = 0, 20, ... 300
55
// floating point version with for loop
66

7-
int main(void)
8-
{
9-
float celsius, fahr;
10-
int lower, upper, step;
7+
int main(void) {
8+
float celsius, fahr;
9+
int lower, upper, step;
1110

12-
lower = 0;
13-
upper = 300;
14-
step = 20;
11+
lower = 0;
12+
upper = 300;
13+
step = 20;
1514

16-
printf("Celsius\tFahr\n");
17-
printf("---------------\n");
15+
printf("Celsius\tFahr\n");
16+
printf("---------------\n");
1817

19-
for (celsius = upper; celsius >= lower; celsius = celsius - step)
20-
{
21-
fahr = (9.0 / 5.0) * celsius + 32.0f;
22-
printf("%3.0f\t\t%6.1f\n", celsius, fahr);
23-
}
18+
for (celsius = upper; celsius >= lower; celsius = celsius - step) {
19+
fahr = (9.0 / 5.0) * celsius + 32.0f;
20+
printf("%3.0f\t\t%6.1f\n", celsius, fahr);
21+
}
2422

25-
return 0;
23+
return 0;
2624
}
2725

2826
// NOTE: Sometimes the for loop can be more explicit and more readable then the
29-
// while loop because it's more compact. The initialization and the incrementation
30-
// of the counter variable is done through the for loop params. However, the while
31-
// loop can be, sometimes, more customizable.
27+
// while loop because it's more compact. The initialization and the
28+
// incrementation of the counter variable is done through the for loop params.
29+
// However, the while loop can be, sometimes, more customizable.

chapter_1/exercise_1_06/verify_expression.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#include <stdio.h>
22

3-
int main(void)
4-
{
5-
printf("value of expression: %d", getchar() != EOF);
6-
return 0;
3+
int main(void) {
4+
printf("value of expression: %d", getchar() != EOF);
5+
return 0;
76
}
87

98
// NOTE: The expression getchar() != EOF is equal with 1 only if input char
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#include <stdio.h>
22

3-
int main(void)
4-
{
5-
printf("EOF: %d", EOF);
6-
return 0;
3+
int main(void) {
4+
printf("EOF: %d", EOF);
5+
return 0;
76
}
87

98
// NOTE: The value of the EOF character is -1, which is an integer.
Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
11
#include <stdio.h>
22

3-
int main(void)
4-
{
5-
int blanks_nr = 0;
6-
int tabs_nr = 0;
7-
int newlines_nr = 0;
3+
int main(void) {
4+
int blanks_nr = 0;
5+
int tabs_nr = 0;
6+
int newlines_nr = 0;
87

9-
char c;
10-
while ((c = getchar()) != EOF)
11-
{
12-
if (c == ' ')
13-
{
14-
++blanks_nr;
8+
char c;
9+
while ((c = getchar()) != EOF) {
10+
if (c == ' ') {
11+
++blanks_nr;
12+
} else if (c == '\t') {
13+
++tabs_nr;
14+
} else if (c == '\n') {
15+
++newlines_nr;
16+
}
1517
}
16-
else if (c == '\t')
17-
{
18-
++tabs_nr;
19-
}
20-
else if (c == '\n')
21-
{
22-
++newlines_nr;
23-
}
24-
}
2518

26-
printf("blanks_nr: %d\ntabs_nr: %d\nnewlines_nr: %d\n",
27-
blanks_nr, tabs_nr, newlines_nr);
19+
printf("blanks_nr: %d\ntabs_nr: %d\nnewlines_nr: %d\n", blanks_nr, tabs_nr,
20+
newlines_nr);
2821

29-
return 0;
22+
return 0;
3023
}

chapter_1/exercise_1_09/copy_io.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
#include <stdio.h>
22

3-
int main(void)
4-
{
5-
int c;
6-
int last_c = '\0';
3+
int main(void) {
4+
int c;
5+
int last_c = '\0';
76

8-
while ((c = getchar()) != EOF)
9-
{
10-
if (c != ' ' || last_c != ' ')
11-
{
12-
putchar(c);
13-
}
7+
while ((c = getchar()) != EOF) {
8+
if (c != ' ' || last_c != ' ') {
9+
putchar(c);
10+
}
1411

15-
last_c = c;
16-
}
12+
last_c = c;
13+
}
1714

18-
return 0;
15+
return 0;
1916
}
Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
11
#include <stdio.h>
22

3-
int main(void)
4-
{
5-
char c;
6-
while ((c = getchar()) != EOF)
7-
{
8-
if (c == '\t')
9-
{
10-
putchar('\\');
11-
putchar('t');
3+
int main(void) {
4+
char c;
5+
while ((c = getchar()) != EOF) {
6+
if (c == '\t') {
7+
putchar('\\');
8+
putchar('t');
9+
} else if (c == '\b') {
10+
putchar('\\');
11+
putchar('b');
12+
} else if (c == '\\') {
13+
putchar('\\');
14+
putchar('\\');
15+
} else {
16+
putchar(c);
17+
}
1218
}
13-
else if (c == '\b')
14-
{
15-
putchar('\\');
16-
putchar('b');
17-
}
18-
else if (c == '\\')
19-
{
20-
putchar('\\');
21-
putchar('\\');
22-
}
23-
else
24-
{
25-
putchar(c);
26-
}
27-
}
2819

29-
return 0;
20+
return 0;
3021
}

0 commit comments

Comments
 (0)