http://www.hackerschool.org/HS_Boards/zboard.php?id=Free_Lectures&no=1441 [º¹»ç]
[switch_upper_lower.c]
Q. ¾ËÆĺªÀ» ÀÔ·Â¹Þ¾Æ ´ë¹®ÀÚ´Â ¼Ò¹®ÀÚ·Î, ¼Ò¹®ÀÚ¸¦ ´ë¹®ÀÚ·Î º¯È¯ÇÏ¿© Ãâ·ÂÇ϶ó.
<ÀÔ/Ãâ·Â ¿¹>
Enter alphabets : aBcDeF
AbCdEf
A. ¿¹Á¦ ¼Ò½º
#include <stdio.h>
#include <string.h>
int main(void) {
char txt[255];
while(1) {
printf("%s", "Enter alphabets : ");
fgets(txt, sizeof(txt), stdin); //fgets¸¦ ÀÌ¿ëÇÏ¿© txt¿¡ Ç¥ÁØÀÔ·ÂÀ» ¹ÞÀ½
int i;
for(i=0; i<strlen(txt)-1; i++) { //txtÀÇ ±æÀÌ - 1(³Î¹®ÀÚ)¸¸Å ·çÇÁ
char ch = txt[i]; //txtÀÇ i¹ø° ¹®ÀÚ¸¦ ch¿¡ ´ëÀÔ
if(ch >= 97 && ch <= 122) //ch°¡ ¼Ò¹®ÀÚÀÏ °æ¿ì
txt[i] -= 32; //txtÀÇ i¹ø° ¹®ÀÚ - 32
if(ch >= 65 && ch <= 90) //ch°¡ ´ë¹®ÀÚÀÏ °æ¿ì
txt[i] += 32; //txtÀÇ i¹ø° ¹®ÀÚ + 32
}
printf("%s", txt);
}
return 0;
}
|
Hit : 7902 Date : 2010/03/20 06:02
|