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

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

by A Lim Han 2023. 1. 28.

# 12์žฅ Mini Project ๋ฌธ์ œ ํ’€์ด

 

 

485p_Mini Project)

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

int main()
{
	FILE* fp;
	fopen_s(&fp, "plain.txt", "w");

	if (fp == NULL)
	{
		printf("ํŒŒ์ผ์„ ์—ด ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.\n");
		exit(0);
	}

	int encrypt_key = 0;
	char plain_text[30];

	printf("ํ‰๋ฌธ์„ ์ž…๋ ฅํ•˜์‹œ์˜ค: ");
	gets_s(plain_text, 30);
	fputs(plain_text, fp);

	printf("์•”ํ˜ธํ™” ํ‚ค: ");
	scanf_s("%d", &encrypt_key);

	int leng = strlen(plain_text);
	int i = 0;

	printf("\n");

	while (1)
	{
		if (plain_text[i] == '\0')
		{
			if (i > leng)
			{
				break;
			}
			else
			{
				plain_text[i] = '\0';
			}
		}
		else
		{
			if (plain_text[i] >= 'A' && plain_text[i] <= 'z')
			{
				plain_text[i] += encrypt_key;

				if (plain_text[i] > 'z')
				{
					plain_text[i] -= 26;
				}
			}
		}
		i++;
	}

	printf("์•”ํ˜ธ๋ฌธ: ");
	for (int k = 0; k < leng; k++)
	{
		printf("%c", plain_text[k]);
	}

	printf("\n");
	fputs(plain_text, fp);

	fclose(fp);
	return 0;
}

์‚ฌ์šฉํ•œ ์•”ํ˜ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜: ์‹œ์ € ์•”ํ˜ธ(์‹œํ”„ํŠธ ์•”ํ˜ธ)