In the space below, write a C function definition for a function named StrLower,
ID: 3840015 • Letter: I
Question
In the space below, write a C function definition for a function named StrLower, which will receive one parameter, a pointer to a null-terminated string (i.e., pointer to char), convert each character in the string to lowercase (using the tolower function from ), and return nothing to the caller. Inside the function definition, you may use a for loop or a while loop. If you use any variables other than the incoming parameter, you must define them locally in the function definition. You may use the strlen function from to find the number of characters in the string, if you wish. You may use either array indexing notation or pointer notation to access the individual characters in the string. Assume that string.h and ctypc.h are already included. Just write the function definition itself. Be sure that your function definition has the appropriate return type, function name, parameter definition, and the complete function body. This function must not ask the user for any input. It must not print anything to the console window. It must just convert all uppercase characters in the string to lowercase characters and then return to the caller.Explanation / Answer
#include <stdio.h>
#include <ctype.h>
#include <string.h>
void StrLower(char s[]) {
int n, i;
n = strlen(s);
for(i=0;i<n;i++){
s[i]=tolower(s[i]);
}
}
int main()
{
char s[100];
printf("Enter the string: ");
scanf("%s", &s);
StrLower(s);
printf("Lower case string is: %s ", s);
return 0;
}
Output:
Enter the string: ABCDeffYUU
Lower case string is: abcdeffyuu