Question: 1 6 . 1 2 The following code reads a string from the keyboard and prints out a version with any uppercase characters converted to

16.12 The following code reads a string from the keyboard and prints out a
version with any uppercase characters converted to lowercase.
However, it has a flaw. Identify it.
#include
#define MAX_LEN 10
char *LowerCase(char *s);
int main(void)
{
char str[MAX_LEN];
printf("Enter a string : ");
scanf("%s", str);
printf("Lowercase: %s
", LowerCase(str));
}
char *LowerCase(char *s)
{
char newStr[MAX_LEN];
for (int index =0; index < MAX_LEN; index++){
if ('A'<= s[index] && s[index]<='Z')
newStr[index]= s[index]+('a'-'A');
else
newStr[index]= s[index];
}
return newStr;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!