编写 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
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP