Demo entry 5287866

Caesar's code

   

Submitted by Zhong Haoyu on Jun 14, 2016 at 14:03
Language: C. Code size: 945 Bytes.

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

#define STR_LEN 100
#define STR_NUM 100
#define WORDS 26

int main()
{
	FILE *fp1 = fopen("D:/miwen.txt", "r");
	char str_1[STR_LEN + 1];
	char str_2[STR_NUM][STR_LEN + 1];
	char str_3[STR_NUM][STR_LEN + 1];
	int i = 0;

	while (!feof(fp1))
	{
		fscanf(fp1, "%s", str_1);
		strcpy(str_2[i], str_1);
		i++;
	}

	fclose(fp1);

	for (int m = 0; m < WORDS; m++)
	{
		for (int p = 0; p < i; p++)
		{
			strcpy(str_1, str_2[p]);
			strlwr(str_1);

			for (int q = 0; q < strlen(str_1); q++)
			{
				if ((str_1[q] >= 97 && str_1[q] <= 122)||(str_1[q] >= 65 && str_1[q] <= 90))
				{
					str_1[q] -= m;
					if ((str_1[q]>90&&str_1[q] < 97)||str_1[q]<65)
					{
						str_1[q] += 26;
					}
				}
			}
			strcpy(str_3[p], str_1);
		}


		for (int q = 0; q < i; q++)
		{
			printf("%s ", str_3[q]);
		}
		printf("\n");
	}
	return 0;
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).