編寫 C 程式,無需使用字串轉換函式,將大寫字母轉換為小寫字母


瞭解無需字串轉換函式如何將大寫字母轉換為小寫字母。

讓我們看看使用轉換函式將大寫字母轉換為小寫的程式,然後您將瞭解我們在程式中所做的事情:

範例

#include <stdio.h>
#include <string.h>
int main(){
   char string[50];
   printf("enter a string to convert to lower case
");    gets(string); /reading the string    printf("The string in lower case: %s
", strlwr(string)); //strlwr converts all upper    to    lower    return 0; }

輸出

enter a string to convert to lower case
CProgramming LangUage
The string in lower case: cprogramming language

現在讓我們看看無需使用預定義函式將大寫字母轉換為小寫的程式:

範例

#include<stdio.h>
void main(){
   //Declaring variable for For loop (to read each position of alphabet) and string//
   int i;
   char string[40];
   //Reading string//
   printf("Enter the string : ");
   gets(string);
   //For loop to read each alphabet//
   for(i=0;string[i]!='\0';i++){
      if(string[i]>=65&&string[i]<=90){
         string[i]=string[i]+32;
      }
   }
   printf("The converted lower case string is : ");
   puts(string);
}

輸出

Enter the string : TUTORIALSPOINT
The converted lower case string is : tutorialspoint

更新於:2021 年 3 月 9 日

8K + 瀏覽量

啟動您的 職業生涯

完成課程認證

開始
廣告