I am trying to convert the string to upper case, e.g. convert test.pdf
to TEST.PDF
. However, when I try to print returned value using printf
, it prints some junk value. What am I doing wrong?
char *covertToUpper(char *str)
{
int i = 0;
int len = 0;
len = strlen(str);
char newstr[len+1];
for(i = 0; str[i]; i++)
{
newstr[i] = toupper(str[i]);
}
//terminate string
newstr[i]= '\0';
return newstr;
}
str
to be changed? If so the code can be made very short.