c语言字符串的一个简单例子,把一个字符串中的小写字母改成大写字母
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                c语言字符串的一个简单例子,把一个字符串中的小写字母改成大写字母
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                把一個字符串中小寫字母改成大寫字母,利用toupper()函數,這個函數定義在 ctype.h 頭文件中
#include <stdio.h> #include <ctype.h> #define LEN 100 void capitalize(char *,int ); int main() { char arr[LEN + 1] = "asdAabdasf*,.PasdfasdfAS1231"; capitalize(arr,LEN + 1); printf("%s",arr);return 0; }void capitalize(char *s,int n) { while(*s != '\0') {if( *s >= 'a' && *s <= 'z'){*s = toupper(*s);}s ++; } }?如果不用 ctype.h中的 toupper函數,那么可以如下:
#include <stdio.h> void capitalize(char *,int ); #define LEN 100 int main() { char arr[LEN + 1] = "asdf as..asdfas..asdfasdfdf"; capitalize(arr,LEN + 1); printf("%s",arr);return 0; } void capitalize(char *s,int n) {for(; *s != '\0';++ s){if(*s >= 'a' && *s <= 'z'){*s -= ('a' - 'A'); }} }?
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的c语言字符串的一个简单例子,把一个字符串中的小写字母改成大写字母的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 关于c++中map插入元素的问题
- 下一篇: c 语言现代方法13章习题6
