Skip to content
Closed
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion chapter_1/exercise_1_02/printf_argument.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdio.h>

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.

return 0;
}
Loading