write a string reversal function in c and write a separate test function
- User
write a string reversal function in c and write a separate test function
Assistant
Here is a simple implementation of a string reversal function in C:
#include <stdio.h> #include <string.h> void reverse_string(char *str) { int len = strlen(str); for (int i = 0; i < len / 2; i++) { char tmp = str[i]; str[i] = str[len - i - 1]; str[len - i - 1] = tmp; } } void test_reverse_string() { char str[] = "Hello, World!"; reverse_string(str); printf("Reversed string: %s\n", str); } int main() { test_reverse_string(); return 0; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.