Skip to content

Conversation

@kkaname
Copy link
Contributor

@kkaname kkaname commented Dec 15, 2025

it is given that we have to check what happens when we put a incorrect escape sequence like \c given in the question. Previous code had "hello, world\c" has the printf argument which just prints 'hello world\c' instead of checking what error does it show for entering incorrect escape sequence. I have also commented the error produced as per the GCC compiler

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an escape-sequence in a sample string so example output displays correctly and avoids misleading warnings.
  • New Features

    • Updated the bit-rotation demo to use a shorter-width integer and a clearer binary display for easier understanding.
  • Documentation

    • Added a note about the previously unrecognized escape sequence to surface a possible compiler warning.

✏️ Tip: You can customize this high-level summary in your review settings.

it is given that we have to check what happens when we put a incorrect escape sequence like \c given in the question. Previous code had "hello, world\\c" has the printf argument which just prints 'hello world\c' instead of checking what error does it show for entering incorrect escape sequence.
I have also commented the error produced as per the GCC compiler
@coderabbitai
Copy link

coderabbitai bot commented Dec 15, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Changed a printf string literal in chapter_1 and rewrote bit-rotation logic in chapter_2: replaced <math.h> with <limits.h>, changed rightrot signature to use unsigned short, added to_binary, simplified rotation logic, and updated main to demonstrate the new functions.

Changes

Cohort / File(s) Summary
Printf argument change
chapter_1/exercise_1_02/printf_argument.c
Modified the printf string literal from "hello, world\\c" to "hello, world\c" and added an inline comment noting the unknown escape sequence \c.
Right-rotation rewrite
chapter_2/exercise_2_08/rightrot.c
Replaced #include <math.h> with #include <limits.h>; changed function signature from unsigned int rightrot(unsigned int x, unsigned int n) to unsigned short rightrot(unsigned short x, int n); added void to_binary(unsigned short n); implemented rotation using w = sizeof(unsigned short)*CHAR_BIT and n %= w; removed legacy printbin and adjusted main to call to_binary for demonstration.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Pay attention to the changed public signature of rightrot (type/parameter changes) and any callers elsewhere in the codebase.
  • Verify to_binary correctness (bit width assumptions, zero handling) and that n wrapping (modulo) behaves as intended for negative or large n.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Correct escape sequence in printf statement' accurately and concisely describes the main change—modifying a printf argument to demonstrate and correct an escape sequence issue.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a01ba79 and e4b721e.

📒 Files selected for processing (1)
  • chapter_2/exercise_2_08/rightrot.c (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bdcee72 and 7c1a3cf.

📒 Files selected for processing (1)
  • chapter_1/exercise_1_02/printf_argument.c (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: C CI
chapter_1/exercise_1_02/printf_argument.c

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


int main(void) {
printf("hello, world\\c");
printf("hello, world\c"); /*prints warning: unknown escape sequence '\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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# First, explore the repository structure
find . -name ".clang-format" -o -name ".clang-format-ignore" -o -name "clang-format.cfg" | head -20

Repository: ohkimur/the-c-programming-language-2nd-edition-solutions

Length of output: 115


🏁 Script executed:

#!/bin/bash
# Check if the file exists and read its content
if [ -f "chapter_1/exercise_1_02/printf_argument.c" ]; then
  echo "=== File found ==="
  cat -n "chapter_1/exercise_1_02/printf_argument.c"
else
  echo "File not found. Searching for similar file names..."
  find . -name "*printf*" -type f 2>/dev/null | head -20
fi

Repository: ohkimur/the-c-programming-language-2nd-edition-solutions

Length of output: 297


🏁 Script executed:

#!/bin/bash
# Check for any clang-format configuration files in the repo
git ls-files | grep -E "(clang-format|\.clang|format\.yaml|format\.json)" || echo "No clang-format files found via git ls-files"

Repository: ohkimur/the-c-programming-language-2nd-edition-solutions

Length of output: 125


🏁 Script executed:

#!/bin/bash
# Read the clang-format configuration
cat .clang-format

Repository: ohkimur/the-c-programming-language-2nd-edition-solutions

Length of output: 133


🏁 Script executed:

#!/bin/bash
# Apply clang-format and see what changes it would make
if command -v clang-format &> /dev/null; then
  echo "=== clang-format would change to: ==="
  clang-format -style=file chapter_1/exercise_1_02/printf_argument.c
else
  echo "clang-format not available, but based on LLVM style:"
  echo "Inline comments should have 1 space, not 5 spaces"
fi

Repository: ohkimur/the-c-programming-language-2nd-edition-solutions

Length of output: 202


🏁 Script executed:

#!/bin/bash
# Verify the \c escape sequence behavior in C
# Check C standard behavior and common compiler outputs
cat <<'EOF'
Escape sequence verification:
- \c is NOT a standard C escape sequence
- Standard C defines: \n, \t, \r, \a, \b, \f, \v, \\, \', \", \?, \0-7 (octal), \x (hex)
- \c is implementation-defined and typically generates a compiler warning
- The exact warning text varies by compiler (GCC vs Clang vs MSVC)

Current code says: "/*prints warning: unknown escape sequence '\c' */"
Issues:
1. "prints warning" is misleading - the compiler emits the warning, not the program
2. Hard-coded GCC diagnostic text is not portable across compilers
3. Spacing before comment violates LLVM clang-format style (5 spaces instead of 1)
EOF

Repository: ohkimur/the-c-programming-language-2nd-edition-solutions

Length of output: 714


Fix inline comment clarity and clang-format spacing

The code correctly introduces an invalid escape sequence, but the inline comment has two issues:

  • The comment states "prints warning" which is misleading—the compiler emits the warning at compile time, not at runtime.
  • The hard-coded GCC diagnostic text is not portable across different compilers.
  • Spacing before the comment violates the repository's LLVM clang-format style (currently 5 spaces; should be 1 space).

Adjust the comment to be compiler-agnostic and fix the spacing:

-    printf("hello, world\c");     /*prints warning: unknown escape sequence '\c' */
+    printf("hello, world\c");  /* compiler warning: invalid escape sequence '\c' */

Then run clang-format to ensure it matches the repository's style configuration.

📝 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"); /*prints warning: unknown escape sequence '\c' */
printf("hello, world\c"); /* compiler warning: invalid escape sequence '\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 inline comment
after the printf call is misleading and misformatted: change the comment to be
compiler-agnostic (e.g., note that the string contains an invalid/unknown escape
sequence and that a compiler may emit a warning) and reduce the spacing before
the comment to a single space to conform to LLVM/clang-format style; after
editing, run clang-format on the file to ensure spacing and style match the
repository configuration.

Removed warning comment about unknown escape sequence.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
chapter_1/exercise_1_02/printf_argument.c (1)

8-8: Clarify comment: compiler warning vs program output and avoid GCC-specific text

The warning is emitted by the compiler at compile time, not “printed” by the program, and the exact wording is compiler-specific. Make the comment compiler-agnostic and describe the invalid escape sequence instead.

Suggested diff:

-// prints warning: unknown escape sequence '\c'
+// This string literal contains an invalid/unknown escape sequence '\c'; the compiler may emit a warning.

Please confirm this aligns with how your C compiler documents invalid escape sequences (e.g., by checking its manual or warning reference).

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c1a3cf and a01ba79.

📒 Files selected for processing (1)
  • chapter_1/exercise_1_02/printf_argument.c (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: C CI
chapter_1/exercise_1_02/printf_argument.c

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


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.

@kkaname kkaname closed this Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant