More actions
No edit summary |
No edit summary |
||
| Line 77: | Line 77: | ||
== 유진 == | == 유진 == | ||
#define _CRT_SECURE_NO_WARNINGS | |||
#include <stdio.h> | |||
#include <string.h> | |||
#include <stdlib.h> | |||
#include <time.h> | |||
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; | |||
} | |||
= 후기 = | = 후기 = | ||
== [[이지수|물주는사람]] == | == [[이지수|물주는사람]] == | ||
Revision as of 07:46, 23 May 2017
◀이전수업▒▒▒▒▒다음수업▶ 새싹교실/2017 새싹교실/2017/꽃밭
실습
실습 1 : 대문자로 바꾸는 함수
- 코드
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
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 <stdio.h>
#include <string.h>
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;
}
과제 소개
과제 제출
현지
혜민
유진
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
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;
}