求解c语言的编程题

来源:百度知道 编辑:UC知道 时间:2024/05/12 03:51:16
Write the funtcion void Cap(char str[]) that when given a string will capitalize any character that is a lower case alphabetic character. Note that the string could contain any number of characters, including numbers, funny symbols, etc. These should remain as they are.

能不能先给我翻译一下呀,我英语不好呵呵,
看看行不行?以我的理解做的

#include "stdio.h"
void Cap(char str[])
{
int i=0,n;
while(str[i]!='\0')
{
if(str[i]>='A'&&str[i]<='Z')
str[i]=str[i]+32;
i++;
}
printf("%s",str);
}

main()
{
char c[1000];
printf("please get some letters:");
scanf("%s",&c);
Cap(c);
}

写一个函数:void Cap(char str[]),该函数将所接收的字符串中的小写字母转换成相应的大写字母。注意字符串可以包含任意多的字符,包含数字、奇怪的符号等,它们应当被保留。
这题目似乎不容易啊。
首先包含任意多的字符,就需要用动态内存分配;str[i]>='A'&&str[i]<='Z';仅仅考虑了ASCII码的情况,对于宽字符和非ASCII编码且又有大小写的字符集来说,可能会出错。