gpt-3.5-turbo-1106· OpenAI
Arena Human Preference 55K
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
Sure! Below is a simple implementation of a string reversal function in C, along with a separate test function to demonstrate its usage:
#include <stdio.h> #include <string.h> void reverseString(char *str) { int length = strlen(str); char temp; for (int i = 0; i < length / 2; i++) { temp = str[i]; str[i] = str[length - i - 1]; str[length - i - 1] = temp; } } void testStringReversal() { char testStr[] = "Hello, World!"; printf("Original string: %s\n", testStr); reverseString(testStr); printf("Reversed string: %s\n", testStr); } int main() { testStringReversal(); return 0; }When you run the program, it will output the original string and its reversed form.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.