Skip to content

Commit b51a3f0

Browse files
committed
Update main function signatures to use 'void' for no parameters across multiple files
- Changed main function declarations from 'int main()' to 'int main(void)' to adhere to modern C standards and avoid compiler warnings. - Updated function prototypes for skip_blanks and skip_comments to explicitly declare no parameters. - Ensured consistent use of data types in loop variables to prevent sign comparison warnings.
1 parent 9a24484 commit b51a3f0

File tree

42 files changed

+143
-86
lines changed

Some content is hidden

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

42 files changed

+143
-86
lines changed

chapter_1/exercise_1_12/copy_io_nl.c

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

3-
int main() {
3+
// Using (void) instead of () explicitly declares that main takes no parameters
4+
// This is the preferred modern C style and avoids compiler warnings
5+
int main(void) {
46
int character;
57
int previous_character = EOF;
68

chapter_2/exercise_2_06/setbits.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
unsigned int setbits(int x, int p, int n, int y);
1111

1212
int main(void) {
13-
unsigned int x = 0b11111111;
14-
unsigned int y = 0b0110;
13+
// Using hexadecimal instead of binary literals (0b...) for C89/C99 compatibility
14+
// 0xFF = 0b11111111, 0x06 = 0b0110
15+
unsigned int x = 0xFF;
16+
unsigned int y = 0x06;
1517

1618
printf(BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(x));
1719
printf(BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(setbits(x, 2, 4, y)));

chapter_2/exercise_2_07/invert.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
unsigned int invert(int x, int p, int n);
1111

1212
int main(void) {
13-
unsigned int x = 0b11010111;
13+
// Using hexadecimal instead of binary literals (0b...) for C89/C99 compatibility
14+
// 0xD7 = 0b11010111
15+
unsigned int x = 0xD7;
1416

1517
printf(BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(x));
1618
printf(BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(invert(x, 1, 4)));

chapter_2/exercise_2_08/rightrot.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ void printbin(unsigned int x);
55
unsigned int rightrot(unsigned int x, unsigned int n);
66

77
int main(void) {
8-
unsigned int x = 0b11110101;
8+
// Using hexadecimal instead of binary literals (0b...) for C89/C99 compatibility
9+
// 0xF5 = 0b11110101
10+
unsigned int x = 0xF5;
911

1012
printbin(x);
1113
printbin(rightrot(x, 5));
@@ -29,7 +31,9 @@ void printbin(unsigned int x) {
2931
unsigned int rightrot(unsigned int x, unsigned int n) {
3032
unsigned int msb_1 = ~(~(unsigned)0 >> 1);
3133

32-
int i;
34+
// Using unsigned int for i to match the unsigned n parameter
35+
// This prevents sign comparison warnings
36+
unsigned int i;
3337
for (i = 0; i < n; ++i) {
3438
if (x & 1) {
3539
x = (x >> 1) | msb_1;

chapter_2/exercise_2_09/bitcount.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ void printbits(unsigned int x);
55
int bitcount(unsigned int x);
66

77
int main(void) {
8-
unsigned int x = 0b011010;
8+
// Using hexadecimal instead of binary literals (0b...) for C89/C99 compatibility
9+
// 0x1A = 0b011010
10+
unsigned int x = 0x1A;
911

1012
printbits(x);
1113
printf("x have %d bits of 1.\n", bitcount(x));

chapter_3/exercise_3_02/escape.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ int main(void) {
2323
}
2424

2525
int get_line(char line[], unsigned int limit) {
26-
int i, c;
26+
// Using unsigned int for i to match the unsigned limit parameter
27+
// This prevents sign comparison warnings
28+
unsigned int i;
29+
int c;
2730
for (i = 0; i < limit - 1 && (c = getchar()) != EOF && c != '\n'; ++i) {
2831
line[i] = c;
2932
}

chapter_4/exercise_4_02/atof.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ int main(void) {
1818
}
1919

2020
int get_line(char line[], unsigned int max_line_len) {
21-
int i = 0, c;
21+
// Using unsigned int for i to match the unsigned max_line_len parameter
22+
// This prevents sign comparison warnings
23+
unsigned int i = 0;
24+
int c;
2225

2326
while (i < max_line_len - 1 && (c = getchar()) != '\n') {
2427
line[i] = c;

chapter_4/exercise_4_10/calculator.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ void clear(void) {
193193
}
194194

195195
int get_line(char line[], unsigned int max_line_len) {
196-
int c, i;
196+
int c;
197+
// Using unsigned int for i to match the unsigned max_line_len parameter
198+
// This prevents sign comparison warnings
199+
unsigned int i;
197200

198201
for (i = 0; i < max_line_len - 1 && (c = getchar()) != EOF && c != '\n';
199202
++i) {

chapter_5/exercise_5_03/strcat.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ void strcat_ptr(char *s, char *t) {
2020
++s;
2121

2222
// copy t to the end of s
23-
while (*s++ = *t++)
23+
// Extra parentheses around assignment suppress compiler warning about
24+
// using assignment as condition (this is intentional and safe here)
25+
while ((*s++ = *t++))
2426
;
2527
}

chapter_5/exercise_5_07/readlines.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void writelines(char *line_ptr[], int nr_of_lines);
1616
void swap(char *v[], int i, int j);
1717
void quick_sort(char *line_ptr[], int left, int right);
1818

19-
int main() {
19+
int main(void) {
2020
int nr_of_lines; // # of input lines read
2121
char stored_lines[MAXSTORE]; // # of chars to be stored for all lines
2222

0 commit comments

Comments
 (0)