Conversation
do not merge
| str[end] = temp; | ||
| start++; | ||
| end--; | ||
| } |
There was a problem hiding this comment.
Pull request overview
This PR appears to be a workflow/learning “test commit” and introduces a small standalone C program under the test directory that reads a string from stdin and reverses it in place.
Changes:
- Added
source/test/testing_purpose.c, a simple interactive C program that reverses a string.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #include <stdio.h> | ||
| #include <string.h> |
There was a problem hiding this comment.
This new C file is missing the standard Apache 2.0 license/header block that appears at the top of other source/test files in this repo. Please add the project’s usual header to keep licensing consistent.
| int start = 0; | ||
| int end = strlen(str) - 1; |
There was a problem hiding this comment.
int end = strlen(str) - 1; can underflow when the input string is empty (strlen==0) and also truncates size_t into int, which is implementation-defined for long strings. Consider using size_t len = strlen(str); and returning early when len < 2, then index with size_t/ptrdiff_t safely.
| int start = 0; | |
| int end = strlen(str) - 1; | |
| if (str == NULL) { | |
| return; | |
| } | |
| size_t len = strlen(str); | |
| if (len < 2) { | |
| return; | |
| } | |
| size_t start = 0; | |
| size_t end = len - 1; |
| printf("Enter a string: "); | ||
| fgets(str, sizeof(str), stdin); | ||
|
|
||
| // Remove newline if present | ||
| str[strcspn(str, "\n")] = 0; | ||
|
|
There was a problem hiding this comment.
The return value of fgets isn’t checked. If stdin is closed/EOF, fgets returns NULL and str remains uninitialized, leading to undefined behavior in strcspn and reverseString. Please handle the NULL case (e.g., print an error and exit).
| int main() { | ||
| char str[100]; | ||
|
|
||
| printf("Enter a string: "); | ||
| fgets(str, sizeof(str), stdin); | ||
|
|
||
| // Remove newline if present | ||
| str[strcspn(str, "\n")] = 0; | ||
|
|
||
| reverseString(str); | ||
| printf("Reversed string: %s\n", str); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
This adds an interactive main() program under source/test/, but the test suite here is built as a single gtest binary (see source/test/Makefile.am and gtest_main.cpp). If this file is only for workflow experimentation, it should be removed before merging; if it’s meant to test string reversal, consider converting it into a gtest unit test instead of prompting on stdin.
| int main() { | |
| char str[100]; | |
| printf("Enter a string: "); | |
| fgets(str, sizeof(str), stdin); | |
| // Remove newline if present | |
| str[strcspn(str, "\n")] = 0; | |
| reverseString(str); | |
| printf("Reversed string: %s\n", str); | |
| return 0; | |
| } |
| @@ -0,0 +1,33 @@ | |||
| #include <stdio.h> | |||
There was a problem hiding this comment.
PR description says "Please do not merge". To avoid accidental merges, consider marking this PR as a Draft or closing it until it’s ready to land.
Working on understanding process workflow
Please do not merge,