
February 17th, 2013, 05:34 AM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 1
Time spent in forums: 30 m 57 sec
Reputation Power: 0
|
|
|
Recursive function help
Hi there guys,
As part of my course work, I'm required to write a recursive function with the following signature:
int cpyUpperCase(const char A[], char B[])
The intention is that the recursive function would go through all elements in A and check if it's upper case and if so.. put that element in B.
The actual function should return the number of upper case letters found.
Please help.
So far, I managed to write a non-recursive version of the function, not sure how to convert to recursion.
Code:
int cpyUpperCase(const char A[], char B[])
{
int counter = 0;
int upperCaseCounter = 0;
int sizeOfA= strlen(A);
for(counter=0; counter<sizeOfA; counter++)
{
if(isupper(A[counter]))
{
upperCaseCounter++;
B = (char*) realloc (B, upperCaseCounter * sizeof(char));
B[upperCaseCounter-1]= A[counter];
}
}
return upperCaseCounter;
}
|