Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new C source file under the unit test tree that implements an interactive string-reversal program.
Changes:
- Introduces
source/test/testing_purpose.cwith areverseString()helper and an interactivemain()that reads from stdin and prints results.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 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 file adds an interactive standalone main() program under source/test, but it is not referenced by source/test/Makefile.am (the unit test build enumerates sources explicitly). If this is intended as a unit test, convert it into a gtest test and add it to PsmSsp_gtest_bin_SOURCES; otherwise consider removing it or relocating it outside the test tree to avoid dead/accidental test artifacts in the repo.
| 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; | |
| } |
| start++; | ||
| end--; | ||
| } | ||
| printf("string reversed : %s\n",str); |
There was a problem hiding this comment.
reverseString performs I/O (printf) in addition to reversing the buffer, and main() prints the reversed string again. Consider keeping reverseString focused on mutation only and letting the caller decide whether/how to print, to avoid duplicated output and make the function reusable in unit tests.
| printf("string reversed : %s\n",str); |
| char str[100]; | ||
|
|
||
| printf("Enter a string: "); | ||
| fgets(str, sizeof(str), stdin); |
There was a problem hiding this comment.
fgets return value is not checked. If stdin is closed or an error occurs, str contents are undefined and strcspn/reverseString will operate on uninitialized data. Handle a NULL return from fgets (e.g., print an error and return non-zero) before using str.
| fgets(str, sizeof(str), stdin); | |
| if (fgets(str, sizeof(str), stdin) == NULL) { | |
| fprintf(stderr, "Error reading input.\n"); | |
| return 1; | |
| } |
| #include <stdio.h> | ||
| #include <string.h> | ||
|
|
||
| void reverseString(char *str) { |
There was a problem hiding this comment.
reverseString has external linkage but appears intended for use only within this file. Mark it static to avoid exporting an unnecessary symbol from the test binary (and potential link conflicts if another test adds the same helper name).
| void reverseString(char *str) { | |
| static void reverseString(char *str) { |
No description provided.