문자열 변환 기능 없이 대문자를 소문자로 변환하는 방법을 알아보기 전에
변환 기능을 사용하여 상위에서 하위로 변환하는 프로그램을 살펴보겠습니다. 그러면 프로그램에서 수행하는 작업을 명확하게 알 수 있습니다. −
예시
#include <stdio.h>
#include <string.h>
int main(){
char string[50];
printf("enter a string to convert to lower case\n");
gets(string); /reading the string
printf("The string in lower case: %s\n", 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