C语言中的toupperfunction

#include  #include  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; } 

这个程序编译得很好,但是当我运行它时,它不输出任何东西。 我在这里失踪了什么?

你没有打印任何东西!

打印toupper()的返回值。

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

你不打印任何东西,所以当然它不会输出任何东西。

 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));