Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion chapter_1/exercise_1_02/printf_argument.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <stdio.h>

int main(void) {
printf("hello, world\\c");
printf("hello, world\c");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix clang-format violation on the printf line

There are trailing spaces after the printf statement, which is what the C CI clang-format check is flagging. Remove them and rerun clang-format on this file.

Suggested diff:

-    printf("hello, world\c");    
+    printf("hello, world\c");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
printf("hello, world\c");
printf("hello, world\c");
🧰 Tools
🪛 GitHub Actions: C CI

[error] 4-4: clang-format violation detected. Code should be clang-formatted [-Wclang-format-violations].

🤖 Prompt for AI Agents
In chapter_1/exercise_1_02/printf_argument.c around line 4, the printf line
contains trailing whitespace that violates the project's clang-format check;
remove the trailing spaces after the printf statement (ensure no extra spaces
after the closing semicolon) and then run clang-format on the file to apply
formatting fixes and verify the CI check passes.

return 0;
}

// prints warning: unknown escape sequence '\c'
65 changes: 32 additions & 33 deletions chapter_2/exercise_2_08/rightrot.c
Original file line number Diff line number Diff line change
@@ -1,48 +1,47 @@
#include <math.h>
#include <limits.h>
#include <stdio.h>

void printbin(unsigned int x);
unsigned int rightrot(unsigned int x, unsigned int n);
/* Exercise 2.8: Write a function rightrot(x, n) that returns the value
* of the integer x rotated to the right by n bit positions.
*/

int main(void) {
// Using hexadecimal instead of binary literals (0b...) for C89/C99
// compatibility 0xF5 = 0b11110101
unsigned int x = 0xF5;
void to_binary(unsigned short n) {
unsigned long i = 0;
int binary[32];
printf("0b");

printbin(x);
printbin(rightrot(x, 5));
if (n == 0) {
printf("0\n");
return;
}

return 0;
while (i < sizeof(unsigned short) * CHAR_BIT) {
binary[i++] = n % 2;
n = n / 2;
}
for (int j = i - 1; j >= 0; j--) {
printf("%d", binary[j]);
}
printf("\n");
}

void printbin(unsigned int x) {
unsigned int n = sizeof(unsigned int);
unsigned short rightrot(unsigned short x, int n) {
unsigned w = sizeof(unsigned short) * CHAR_BIT;
n %= w;

printf("0b");
return (x >> n) | (x << (w - n));
}

int i;
for (i = n * 8 - 1; i >= 0; --i) {
(x & (unsigned int)pow(2, i)) ? putchar('1') : putchar('0');
}
int main(void) {
unsigned short x;
x = 55;

putchar('\n');
}
printf("x = %d -->", x);
to_binary(x);

unsigned int rightrot(unsigned int x, unsigned int n) {
unsigned int msb_1 = ~(~(unsigned)0 >> 1);

// Using unsigned int for i to match the unsigned n parameter
// This prevents sign comparison warnings
unsigned int i;
for (i = 0; i < n; ++i) {
if (x & 1) {
x = (x >> 1) | msb_1;
} else {
x = (x >> 1);
}
}
to_binary(rightrot(x, 3));

return x;
return 0;
}

// NOTE: The rightrot function rotate the entire unsigned int var and if we
Expand Down
Loading