언어 자료구조 알고리즘/C언어 예제
[C언어 소스] 대소문자 변환
언제나휴일
2016. 4. 3. 15:12
반응형
[C언어 소스] 대소문자 변환
//대문자는 소문자로 소문자는 대문자로
#include <stdio.h>
int main(void)
{
char str[100]="This
is a test sentence. Hello World!";
int i;
printf("원문: %s\n",str);
for(i=0;str[i];
i++)
{
if((str[i]>='a')&&(str[i]<='z'))//if(islower(str[i]))
{
str[i]
= str[i]-'a'+'A';
}
else
{
if((str[i]>='A')&&(str[i]<='Z'))//if(isupper(str[i]))
{
str[i]
= str[i]-'A'+'a';
}
}
}
printf("변환 후:
%s\n",str);
return 0;
}
반응형