Code:
char MakeBig(char c) /*input: letter. output: CAP letter.*/
{
if (c >=97 && c<=122)
c-=32;
return c;
}
/*------------------------------------------*/
char *trim(char *str)
/*input: a sentence*/
/*output: the sentence without spaces, and post-space letters capped.*/
{
char *str2;
int str2l=0;
int Big=1;
str2=(char *)malloc((strlen(str)+1)*sizeof(char))
if str2=='\0'
{
printf("Allocation failed!");
exit(0);
}
for (i=0; i<strlen(str); i++)
if (str[i]==' ')
Big=1;
else
if (Big==1)
{
str2[str2l]=MakeBig(str[i]);
Big=0;
str2l++;
}
else
{
str2[str2l]=str[i];
str2l++;
}
str2[str2l]='\0';
/*LINE IN QUESTION FOLLOWS*/
free(&str2[str2l+1]);
return str2;
}
/*afternote: the idea was of course to release any spare memory.
Would this be the right way to do it? If not, why?
and how to alternatively implement the solution?*/
Those are 2 functions, the program wasn't written.
My questions are outlined in the last comment.
Expecting your reply,
-Sp00nk.