# include <stdio.h>

# include <string.h>

# define LEN 30

//=======================

typedef struct {

char strValue[LEN];

}NAVER;

//=======================

void _init_(NAVER* p); //           func (1)

void _menu_(); //                   func (2)

void toupper(char[]); // func (3)

void tolower(char[]); // func (4)

//=======================

int main(void) { // MAIN FUNCTION 

NAVER sNode;

int choice;

_init_(&sNode);

while (1) {

rewind(stdin);

printf("문자열을 입력하시오 : ");

gets(sNode.strValue);


_menu_(); // function call


printf("번호를 선택하시오. >> ");

scanf("%d", &choice);

switch (choice) {

case 1: toupper(sNode.strValue); break; // 대문자로 변환

case 2: tolower(sNode.strValue); break; // 소문자로 변환

case 0: goto END_;

}

} // endWhile

END_:

printf("문자열 변환 프로그램을 종료합니다.\n");

return 0;

} // END OF MAIN FUNCTION

//=======================

void _init_(NAVER* p) { // func (1)

strcpy(p->strValue, "\0");

} // END OF _INIT_ FUNCTION 

  //=======================

void _menu_() { //         func (2)

printf("1. 대문자로 변환 \n");

printf("2. 소문자로 변환 \n");

printf("3. 프로그램 종료 \n");

printf("\n\n");

} // END OF _menu_ FUNCTION

  //=======================

void toupper(char p[]) { // func (3)

// 소문자를 대문자로 변환 

// ASCII (a:97/ A:65)

int i; // index

printf("변환된 문자열 : ");

for (i = 0; i < strlen(p); i++) {

if (p[i] >= (int)'a' && p[i] <= (int)'z') {

p[i] = (char)((int)p[i] - 32);

}

} // endfor

printf("%s\n", p);

} // END OF FromLowerToUpper FUNCTION

  //=======================

void FromUpperToLower(char p[]) {

// 대문자를 소문자로 변환

int i; // index

printf("변환된 문자열 : ");

for (i = 0; i < strlen(p); i++) {

if (p[i] >= (int)'A' && p[i] <= (int)'Z') {

p[i] = (char)((int)p[i] + 32);

}

} // endfor

printf("%s\n", p);

} // END OF FromUpperToLower FUNCTION 

'언어 > c언어' 카테고리의 다른 글

더블릿 문제  (0) 2018.11.27
네이버 지식인 풀이 (c)  (0) 2018.11.24
네이버 풀이  (0) 2018.11.19
더블릿 풀이 c언어 pie 문제  (0) 2018.11.18
선택정렬  (0) 2018.11.18