[새싹교실/2017/꽃밭/0516|◀이전수업]▒▒▒▒▒[새싹교실/2017/꽃밭/0530|다음수업▶] [새싹교실/2017] [새싹교실/2017/꽃밭] [[TableOfContents]] = 실습 = == 실습 1 : 대문자로 바꾸는 함수 == * 코드 {{{ #define _CRT_SECURE_NO_WARNINGS #include #include void toUpper(char* str); int main() { char input[100]; printf("\n 문자열을 입력하세요(영문자로만 공백없이) : "); gets(input); toUpper(input); printf("\n 변환된 문자열 : "); puts(input); return 0; } //알파벳 소문자를 대문자로 변환하는 함수 void toUpper(char* str){ } }}} == 실습 2 : 내가 좋아하는 색깔은? == {{{ #include "header.h" #ifdef String_Quiz #define _CRT_SECURE_NO_WARNINGS #include #include int main() { char input[7][10] = { "red", "blue", "orange", "green", "black", "white", "pink" }; char* computerColor = input[random]; //computerColor : 컴퓨터가 좋아하는 색깔 char* comp = "Computer", *user = "User"; srand(time(NULL)); int random = rand() % 7; //컴퓨터가 좋아하는 색깔 생성하기 printf("%10s : what is your favorite color? ", comp); //문자열을 선언해서, strcpy로 "My favorite color is "로 초기화합니다. //gets로 내가 좋아하는 색을 입력받고 //strcat을 써서 "My favorite color is <색깔이름>"이라는 문자열을 만듭니다. printf("%10s : ", user); //완성된 문자열을 여기서 출력해주세요. if (/* 만약에 컴퓨터와 내가 좋아하는 색깔이 같다면(strcmp를 사용) */){ printf("%10s : We like same color!\n", comp); } else{ printf("%10s : I don't like that color. I like %s\n", comp, computerColor); } return 0; } }}} = 과제 소개 = = 과제 제출 = == 현지== #include #include #define _CRT_SECURE_NO_WARNINGS #include #include int main() { char input[7][10] = { "red", "blue", "orange", "green", "black", "white", "pink" }; char* comp = "Computer", *user = "User"; srand(time(NULL)); int random = rand() % 7; //컴퓨터가 좋아하는 색깔 생성하기 char* computerColor = input[random];//computerColor : 컴퓨터가 좋아하는 색깔 printf("%10s : what is your favorite color? ", comp); char str1[100]; char str2[100]; strcpy(str1, "My favorite color is"); gets(str2); //문자열을 선언해서, strcpy로 "My favorite color is "로 초기화합니다. //gets로 내가 좋아하는 색을 입력받고 //strcat을 써서 "My favorite color is <색깔이름>"이라는 문자열을 만듭니다. printf("%10s : %s", user,strcat(str1,str2)); //완성된 문자열을 여기서 출력해주세요. if (strcmp(computerColor,str2)==0) { printf("%10s : We like same color!\n", comp); } else { printf("%10s : I don't like that color. I like %s\n", comp, computerColor); } return 0; } == 현지 == {{{ #include #include #define _CRT_SECURE_NO_WARNINGS #include #include int main() { char input[7][10] = { "red", "blue", "orange", "green", "black", "white", "pink" }; char* comp = "Computer", *user = "User"; srand(time(NULL)); int random = rand() % 7; //컴퓨터가 좋아하는 색깔 생성하기 char* computerColor = input[random];//computerColor : 컴퓨터가 좋아하는 색깔 printf("%10s : what is your favorite color? ", comp); char str1[100]; char str2[100]; strcpy(str1, "My favorite color is"); gets(str2); //문자열을 선언해서, strcpy로 "My favorite color is "로 초기화합니다. //gets로 내가 좋아하는 색을 입력받고 //strcat을 써서 "My favorite color is <색깔이름>"이라는 문자열을 만듭니다. printf("%10s : %s", user,strcat(str1,str2)); //완성된 문자열을 여기서 출력해주세요. if (strcmp(computerColor,str2)==0) { printf("%10s : We like same color!\n", comp); } else { printf("%10s : I don't like that color. I like %s\n", comp, computerColor); } return 0; } }}} == 유진 == {{{ #define _CRT_SECURE_NO_WARNINGS #include #include #include #include int main() { char input[7][10] = { "red", "blue", "orange", "green", "black", "white", "pink" }; char* comp = "Computer", *user = "User"; srand(time(NULL)); int random = rand() % 7; //컴퓨터가 좋아하는 색깔 생성하기 char* computerColor = input[random]; //computerColor : 컴퓨터가 좋아하는 색깔 printf("%10s : what is your favorite color? \n", comp); //문자열을 선언해서, strcpy로 "My favorite color is "로 초기화합니다. char str[50]; strcpy(str, "My favorite color is "); //gets로 내가 좋아하는 색을 입력받고 char color[10]; gets(color); //strcat을 써서 "My favorite color is <색깔이름>"이라는 문자열을 만듭니다. strcat(str, color); printf("%10s : ", user); //완성된 문자열을 여기서 출력해주세요. printf("%s\n", str); if (/* 만약에 컴퓨터와 내가 좋아하는 색깔이 같다면(strcmp를 사용) */strcmp(computerColor,color)==0) { printf("%10s : We like same color!\n", comp); } else{ printf("%10s : I don't like that color. I like %s\n", comp, computerColor); } return 0; } }}} = 후기 = == [이지수|물주는사람] == 부족하고 서툴지만 예쁜 새싹들이 잘 들어주고 따라와주어 고맙습니다. 실습이 조금 난해했던 것 같네요. 다음엔 더 재미있고 깔끔한 실습예제를 들고와야겠습니다. == 유진 == 전에 문자열 부분은 거의 알지 못했는데, 이번에 문자열에 대해 배울 수 있어서 다음 프로그래밍 실습 시간에는 스스로 할 수 있을 것 같다. 문자열 함수가 다양하고 많은 기능을 갖고 있다는 것을 알 수 있었다. == 현지 == 전혀 몰랐던 새로운 내용을 배워서 신기했다. 어렵긴 하지만 재미있었다! == 혜민 == 많이 쓰이는 함수 strlen, strcpy, strcat, strcmp의 사용법을 알게 되었고 사용해서 실습도 해보니 더욱 이해가 잘되었다. 스페이스 공간을 다른 문자로, 영문자를 대문자로 바꾸는 방법도 알게되어 유익했다. ------------ [새싹교실/2017/꽃밭/0516|◀이전수업]▒▒▒▒▒[새싹교실/2017/꽃밭/0530|다음수업▶] [새싹교실/2017] [새싹교실/2017/꽃밭]