编程:小写换大写

来源:百度知道 编辑:UC知道 时间:2024/06/05 23:43:14
Please write a main program and a function void cov(char *s)
that all characters of the string are converted the upper case。
Example:the original string is:AbCd,the string after modified is:ABCD.

#include<stdio.h>
#define N 50
void cov(char *s){
int i=0;
while(s[i]!='\0'){
if(s[i]>='a'&&s[i]<'z')
s[i]-=32;
i++;
}
}
void main(){
char s[N];
int i=0;
printf("输入字符串\n");
scanf("%s",&s);
printf("转换前的字符串为:%s\n",s);
cov(s);
printf("转换后的字符串为:%s\n",s);
}

# include<stdio.h>
# include<ctype.h>
void cov(char *s)
{
int i;
for(i=0;s[i]!=0;i++)
toupper(s[i]);
}
void main()
{
char ch[100];
scanf("%s",ch);
cov(ch);
printf("%s\n",ch);
}