I've been tasked to write a recursive function in C that changes a string of any chars to all caps (without using toupper()
or any other function for that matter).
This is the previous code and attempt to solve the question:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char* allCapStringRec(char str[])
{
if (str[0] == '\0' )
return 0;
if (str[0] >= 'a' && str[0] <= 'z')
str[0] = str[0] - 32;
return allCapStringRec(str+1);
}
The code needs to compile successfully through a "test" to check the code - The function works by itself but doesn't complete that testing.
The testing:
void Test3(char str[], char expected[], int dec)
{
char *result = allCapStringRec(str);
if (strcmp(result, expected) != 0)
printf("allCapStringRec => Your Output is %s, Expected: %s\n", result, expected);
}
int main()
{
Test3("123321", "123321", 4);
Test3("abBba", "ABBBA", 4);
Test3("ab$cd", "AB$CD", 4);
printf("done");
return 0;
}
my output:
dupCapStringRec => Your Output is , Expected: 123321
Sorry for all the edits, it's my first question here. I need help knowing what I'm doing wrong:)