判断字符串中的标点符号和大小写转换

#include<stdio.h>
#include<ctype.h>
#include<string.h>
#define SZIE 5 

void ToUpper(char * st);
int PunctCount(char * st);
void ToLower(char * st);

int main(){
    char string[SZIE + 1];
    fgets(string, SZIE + 1, stdin);
    char * find = strchr(string, '\n');
    
    //判断字符串中是否用换行符,有替换成\0空字符 
    if(find){
        *find = '\0';
    }
    
    puts(string);
    ToUpper(string);
    puts(string);
    ToLower(string);
    puts(string);
    printf("这段字符串中有%d个标点符号。\n", PunctCount(string));
}

void ToUpper(char * st){
    while(*st){
        *st = toupper(*st);
        st++;
    }
}

void ToLower(char * st){
    while(*st){
        *st = tolower(*st);
        st++;
    }
}


int PunctCount(char * st){
    int ct = 0;
    while(*st){
        if(ispunct(*st))
            ct++;
        st++;
    }
    return ct;
}

 

posted @ 2022-07-04 07:46  星雨boy  阅读(104)  评论(0)    收藏  举报