C语言中ctype.h函数的用法,请问这两个代码的区别是什么,为什么第一个代码正常运行,第二个代码尝试将convertToUppercase函数写入main函数,写入后发生错误,无法运行。
第一个代码如下:
#include <stdio.h>
#include<ctype.h>
#include<string.h>
void convertToUppercase(char*sPtr);
int main() {
char string[20]="happy birthday";
convertToUppercase(string);
printf("%s",string);
return 0;
}
void convertToUppercase(char*sPtr){
while(*sPtr!='\0'){
if(islower(*sPtr))
*sPtr=toupper(*sPtr);
++sPtr;
}
}
正常运行,输出:HAPPY BIRTHDAY
第二个代码如下:
#include <stdio.h>
#include<ctype.h>
#include<string.h>
int main() {
char string[20]="happy birthday";
while(*string!='\0'){
if(islower(*string))
*string=toupper(*string);
++string;
}
printf("%s",string);
return 0;
}
无法运行