U E D R , A S I H C RSS

새싹교실/2017/꽃밭/0523 (rev. 1.7)

새싹교실/2017/꽃밭/0523

1. 실습



1.1. 실습 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){

}

1.2. 실습 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;
}

2. 과제 소개



3. 과제 제출

3.1. 현지


3.2. 혜민


3.3. 유진

#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;
}

4. 후기

4.2. 유진


4.3. 현지


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:30:06
Processing time 0.0348 sec