Using C11, implement the function to_upper (void *to_upper(const char *str), Returns a…
- User
Using C11, implement the function to_upper (void *to_upper(const char *str), Returns a copy of the string (str) converted to uppercase. In case of an error, returns NULL). It is forbidden to use string.h and ctype.h
Assistant
#include <stdbool.h> char *to_upper(const char *str) { int len = 0; char *result = malloc(sizeof(char) * (1 + strlen(str))); if (result == NULL) { return NULL; } for (int i = 0; str[i] != '\0'; i++) { if (str[i] >= 'a' && str[i] <= 'z') { result[len++] = str[i] - 'a' + 'A'; } else { result[len++] = str[i]; } } result[len] = '\0'; return result; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.