visheshrwl / ccwc

0 stars 0 forks source link

Improve Handling of Command-Line Arguments and Stdin Input #1

Open visheshrwl opened 2 months ago

visheshrwl commented 2 months ago

Description:

The current implementation of the ccwc utility has some issues with handling command-line arguments and stdin input. These issues cause unexpected behavior and incorrect results in certain scenarios.

Issues Identified:

Incorrect Usage Message: The usage message appears even when the input is correct. The logic should correctly determine when to display the usage message.

Improper Handling of stdin: When no filename is provided, the program does not properly handle stdin input. The functionality should allow reading from stdin and correctly count lines, words, characters, and bytes.

Inconsistent Word Count Calculation: The word count calculation sometimes produces incorrect results. Ensure that the word counting logic accurately splits and counts words.

Proposed Solution:

Correct Usage Message Logic: Adjust the logic to only display the usage message when the input is actually incorrect.

Refactor stdin Handling: Ensure that when no filename is provided, the program reads from stdin and correctly processes the input for counting lines, words, characters, and bytes.

Fix Word Count Calculation: Review and correct the word counting logic to ensure accurate word counts.

Steps to Reproduce:

Run the program with only an option (e.g., ./ccwc -w) and observe the output. Run the program with stdin input (e.g., echo "Hello, world!" | ./ccwc -w) and verify the counts. Test the word count with a file containing multiple lines and words.

### Expected Behavior: The usage message should only appear when the input is incorrect. The program should correctly handle stdin input and produce accurate counts. The word count should be accurate and consistent.

### Additional Context: This issue is critical for ensuring the reliability and correctness of the ccwc utility. Ensure to add relevant tests to cover these scenarios once the fixes are implemented.

github-actions[bot] commented 2 months ago

Hi there! 👋 Thank you for opening your first issue in this project! We truly appreciate your effort in making this repository better. Your feedback and contributions are invaluable to us. If you have any questions or need any assistance, don't hesitate to ask. Welcome aboard, and happy contributing! 🚀

github-actions[bot] commented 2 hours ago

Stale issue message