-
-
Notifications
You must be signed in to change notification settings - Fork 140
Implemented the loop for reading input into a string without using th… #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…e relational operators. As per asked in the excercise question, I have implemented the loop using while loop and break statement without using any relational operator(&& and ||).
WalkthroughA loop control structure refactoring in a single exercise file. Replaced conditional-based loop logic with a while(1) infinite loop containing explicit break conditions for EOF, newline, and buffer limit scenarios, and restructured input accumulation using else-if branching. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🔇 Additional comments (1)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (1)
chapter_2/exercise_2_02/loop.c (1)
9-13: Optional: Consider removing commented-out code.The commented code from the previous implementation provides useful context but could be removed for cleaner code. The NOTE at lines 40-45 already explains the multiplication approach.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
chapter_2/exercise_2_02/loop.c(1 hunks)
🔇 Additional comments (1)
chapter_2/exercise_2_02/loop.c (1)
15-31: Implementation successfully avoids relational operators, but needs fixes.The while(1) loop with separate break conditions successfully avoids using
&&and||operators as required by the exercise. The buffer overflow protection logic (lines 16-18) is correct.However, the critical bug on line 20 must be fixed before this implementation is correct.
| else if (c == EOF){ | ||
| printf("\n"); | ||
| break; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Questionable: Extra newline printed on EOF.
Lines 25-28 print a newline when EOF is encountered, but not for other exit conditions (newline or buffer full). This creates inconsistent output behavior.
Consider whether this extra newline is necessary or if EOF should be handled like the newline case (just break).
🤖 Prompt for AI Agents
In chapter_2/exercise_2_02/loop.c around lines 25 to 28, the code prints an
extra newline when c == EOF which causes inconsistent output compared to other
exit conditions; remove the printf("\n") so EOF is handled the same as the
newline/buffer-full cases (just break), or restructure the branch to break
immediately on EOF without emitting any characters.
|
@ohkimur So i have implemented the new changes, and as per you said earlier you can merge the file. |
…e relational operators.
As per asked in the excercise question, I have implemented the loop using while loop and break statement without using any relational operator(&& and ||).
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.