Maison  >  Article  >  développement back-end  >  Écrivez un programme C pour convertir les lettres majuscules en lettres minuscules sans utiliser de fonctions de conversion de chaîne

Écrivez un programme C pour convertir les lettres majuscules en lettres minuscules sans utiliser de fonctions de conversion de chaîne

王林
王林avant
2023-08-29 14:45:061327parcourir

Écrivez un programme C pour convertir les lettres majuscules en lettres minuscules sans utiliser de fonctions de conversion de chaîne

在了解如何在不使用字符串转换函数的情况下将大写字母转换为小写字母之前,让我们来看一下使用转换函数将大写字母转换为小写字母的程序,然后您将清楚我们在程序中所做的事情:

示例

#include <stdio.h>
#include <string.h>
int main(){
   char string[50];
   printf("enter a string to convert to lower case</p><p>");
   gets(string); /reading the string
   printf("The string in lower case: %s</p><p>", 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]!=&#39;\0&#39;;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

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Déclaration:
Cet article est reproduit dans:. en cas de violation, veuillez contacter admin@php.cn Supprimer