๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
โœ’๏ธ C Programming/๋ˆ„๊ตฌ๋‚˜ ์‰ฝ๊ฒŒ ์ฆ๊ธฐ๋Š” C ์–ธ์–ด ์ฝ˜์„œํŠธ_๊ฐœ์ • 3ํŒ

[๋ˆ„๊ตฌ๋‚˜ ์‰ฝ๊ฒŒ ์ฆ๊ธฐ๋Š” C ์–ธ์–ด ์ฝ˜์„œํŠธ - ๊ฐœ์ • 3ํŒ] 10์žฅ Programming ํ’€์ด (2)

by A Lim Han 2023. 1. 25.

# 10์žฅ Programming ํ’€์ด (2)

 

414p_7๋ฒˆ)

#include <stdio.h>
#include <string.h>

void trim_right(char s[])
{
	for (int i = (strlen(s) - 1); i >= 0; i--)
	{
		if (s[i] == ' ')
		{
			s[i] = '?';
		}
	}

	printf("๊ณต๋ฐฑ ๋ฌธ์ž๋ฅผ ์ œ๊ฑฐํ•œ ํ…์ŠคํŠธ: ");

	for (int i = 0; i < strlen(s); i++)
	{
		if (s[i] != '?')
		{
			printf("%c", s[i]);
		}
	}
}

int main()
{
	char array[20] = { "She loves it." };
	trim_right(array);

	return 0;
}

 

 

 

 

415p_8๋ฒˆ)

#include <stdio.h>
#include <string.h>

void trim_left(char array_2[])
{
	for (int i = 0; i < strlen(array_2); i++)
	{
		if (array_2[i] == ' ')
		{
			array_2[i] = '*';
		}
	}

	printf("๊ณต๋ฐฑ ๋ฌธ์ž๋ฅผ ์ œ๊ฑฐํ•œ ํ…์ŠคํŠธ: ");

	for (int i = 0; i < strlen(array_2); i++)
	{
		if (array_2[i] != '*')
		{
			printf("%c", array_2[i]);
		}
	}
}

int main()
{
	char array[20] = { "What is it?" };
	trim_left(array);

	return 0;
}

 

 

 

 

415p_9๋ฒˆ)

#include <stdio.h>
#include <string.h>
#include <ctype.h>

void capital(char s[])
{
	printf("์ˆ˜์ •๋œ ๋ฌธ์ž์—ด: ");

	for (int k = 0; k < strlen(s); k++)
	{
		if ('a' <= s[0] || s[0] <= 'z')	// ์†Œ๋ฌธ์ž --> ๋Œ€๋ฌธ์ž
		{
			s[0] = toupper(s[0]);
		}

		printf("%c", s[k]);
	}
}

int main()
{
	char array1[100];

	printf("๋ฌธ์ž์—ด์„ ์ž…๋ ฅํ•˜์‹œ์˜ค: ");
	gets_s(array1, 100);

	capital(array1);

	return 0;
}

 

 

 

 

415p_10๋ฒˆ)

#include <stdio.h>
#include <string.h>

int main()
{
	char array[100];
	int cnt = 1;

	printf("๋ฌธ์ž์—ด์„ ์ž…๋ ฅํ•˜์‹œ์˜ค: ");
	gets_s(array, 100);

	for (int i = 0; i < strlen(array); i++)
	{
		if (array[i] != array[strlen(array) - 1 - i])
		{
			printf("%s๋Š” ํšŒ๋ฌธ์ด ์•„๋‹™๋‹ˆ๋‹ค.", array);
			cnt = 0;
			break;
		}
	}

	if (cnt != 0)
	{
		printf("%s๋Š” ํšŒ๋ฌธ์ž…๋‹ˆ๋‹ค.", array);
	}

	return 0;
}

 

 

 

 

415p_11๋ฒˆ)

#include <stdio.h>
#include <string.h>

int main()
{
	char a[100];

	printf("ํŒŒ์ผ๋ช…์˜ ์ฒซ ๋ถ€๋ถ„์„ ์ž…๋ ฅํ•˜์‹œ์˜ค: ");
	gets_s(a, 100);

	for (int i = 0; i < 5; i++)
	{
		printf("%s%d.png ", a, i);
	}

	printf("\n");

	return 0;
}

 

 

 

 

416p_12๋ฒˆ)

#include <stdio.h>
#include <string.h>

char username[10];
char usercoun[20];

int main()
{
	char sayhello[] = { "์•ˆ๋…•ํ•˜์„ธ์š”!" };
	char bye[] = { "๋‹˜, ๋‹ค์Œ์— ๋‹ค์‹œ ๋งŒ๋‚˜์š”!" };
	char name[] = { "์ œ ์ด๋ฆ„์€ AL์ด์—์š”. ๋‹น์‹ ์˜ ์ด๋ฆ„์€ ๋ฌด์—‡์ธ๊ฐ€์š”?" };
	char saynamehello[] = {"๋‹˜ ๋ฐ˜๊ฐ‘์Šต๋‹ˆ๋‹ค^^"};
	char country[] = { "์ €๋Š” ํ•œ๊ตญ์—์„œ ์™”์–ด์š”." };
	char ask_country[] = { "๋‹˜์€ ๋ชจ๊ตญ์ด ์–ด๋””์‹ ๊ฐ€์š”?" };
	char hello_country[] = { "๋‹˜์€ ํ•œ๊ตญ์ธ์ด์‹œ๊ตฐ์š”!" };
	int cnt = 1;

	while (cnt != 0)
	{
		printf("> ");
		char input[100];
		gets_s(input, 100);

		for (int i = 0; i < strlen(input); i++)
		{
			if (input[i] == 'e' && input[i + 1] == 'x')
			{
				printf("%s%s\n", username, bye);
				cnt = 0;
				break;
			}
		}

		for (int i = 0; i < strlen(input); i++)
		{
			if (input[i] == 'h' && input[i + 1] == 'e' && input[i + 2] == 'l')
			{
				printf("%s\n", sayhello);
			}
			else if (input[i] == 'n' && input[i + 1] == 'a')
			{
					printf("%s\n", name);
					printf("> ");
					gets_s(username, 10);
					
					printf("%s%s\n", username, saynamehello);
			}
			else if (input[i] == 'f' && input[i + 1] == 'r' && input[i + 2] == 'o')
			{
				printf("%s\n", country);
				printf("%s%s\n", username, ask_country);

				printf("> ");
				gets_s(usercoun, 20);

				printf("%s%s\n", username, hello_country);
			}
		}
	}

	return 0;
}