문제

#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?

도움이 되었습니까?

해결책

You are not printing anything!

Print the return value of toupper().

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

다른 팁

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

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));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top