toupper function in C

懵懂的女人 提交于 2019-12-24 12:24:30

问题


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

char* strcaps(char* s)
{
        while (*s != '\0')
        {
                toupper(*s);
                s++;
        }
        return s;
}

.

int main()
{
        char makeCap[100];
        printf("Type what you want to capitalize: ");
        fgets(makeCap, 100, stdin);
        strcaps(makeCap);
        return 0;
}

this program compiles just fine, but when I run it, it doesn't output anything. what am i missing here?


回答1:


You are not printing anything!

Print the return value of toupper().

        printf("%c",toupper(*s));



回答2:


You don't print anything, so of course it won't output anything.




回答3:


char* strcaps(char* s){
    char *p;
    for (p=s; *p; ++p)
        *p = toupper(*p);//maybe you want to change the original
    return s;//your cord : return address point to '\0'
}
...
//main
printf("%s", strcaps(makeCap));


来源:https://stackoverflow.com/questions/22598292/toupper-function-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!