題目描述 LeetCode 709
Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.
Example 1:
Input: "Hello"
Output: "hello"
Example 2:
Input: "here"
Output: "here"
Example 3:
Input: "LOVELY"
Output: "lovely"
題目解讀
- 輸入一個字符串,將這個字符串中的大寫字母轉化為小寫字母輸出,然后返回轉化后的字符串
解題思路
- 依次循環(huán),將大寫字母轉化為小寫字母
Code
# include<stdio.h>
# include<string.h>
char* toLowerCase(char* str)
{
int i;
int len;
len = strlen(str);
for (i = 0; i < len; i ++)
{
if ( str[i] >= 'A' && str[i] <= 'Z')
{
str[i] = str[i] + 32;
}
}
return str;
}
int main()
{
char s[10] = {"HELLOdd"};
char *temp;
temp = toLowerCase(s);
printf("%s\n", temp);
}

思考
- 簡單題目...