【问题标题】:string can't convert lowercase to upper case as c program [closed]字符串无法将小写字母转换为大写字母作为c程序[关闭]
【发布时间】:2012-09-15 10:41:14
【问题描述】:

如何使用toupper 函数转换字符串?这不起作用。

#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main(){
    char ch[20];
    printf("\nEnter Your String :");
    gets(ch);

    int i=0;
    for(i=0;ch[i] !='\0';i++)
    {
        putchar(toupper(ch[i]));
        putchar(ch[i]);
    }

    return 0;
}

这个程序输出大写和小写我只想大写输出。我无法捕捉到我的逻辑错误。请帮我弄清楚逻辑概念

【问题讨论】:

  • 怎么不行?你期望什么输出,你会得到什么?
  • 什么不起作用?你得到什么输入和输出?
  • 你的程序works as coded :)

标签: c string uppercase


【解决方案1】:

我认为这会奏效

for(i=0;ch[i] !='\0';i++)
{
    ch[i]=toupper(ch[i]);
}

//print the string with uppercase

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-04
    • 2015-07-28
    • 1970-01-01
    • 2018-06-16
    • 2015-06-17
    • 1970-01-01
    • 2015-08-07
    相关资源
    最近更新 更多