// james lancaster
// 14 march 2000
// 10-3

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

char encode_char(char ch, int val)// self evident
{
ch = ch + val;
return ch;
}
// I don't comment. If it was hard to program, it should be hard to understand. --unknown (to me)
char decode_char(char ch, int val)// self evident
{
ch = ch - val;
return ch;
}
void decode_line()// ditto last statement
{
	int val;
	char line[101];
	int x;
	x=0;
	while (x < 101) {
	line[x]=15;
	x++;
	}
	x = 0;
	puts("Enter text to be decoded (up to 100 characters with no spaces.)");
	scanf("%s", &line);
	puts("Enter key for text");
	scanf("%d", &val);
	//geting data
	do {

	line[x]=decode_char(line[x], val);
	
	x++;

	} while (int(line[x]) != 15-val &&x != 101);
	//encoding
	x=0;
	do 
	{
	
		printf("%c", line[x]);
		x++;

	}while (int(line[x]) != 15-val && x != 101);
	puts("");
	//printing


}

void decode_file()
{
// not done
}

void encode_line()//Hmm. I wonder.
{
	int val;
	char line[101];
	int x;
	x=0;
	while (x < 101) {
	line[x]=0;
	x++;
	}
	x = 0;
	puts("Enter text to be encoded (up to 100 characters with no spaces.)");
	scanf("%s", &line);
	puts("Enter key for text");
	scanf("%d", &val);	//geting data
	do {
	line[x]=encode_char(line[x], val);
	x++;
	} while (line[x] != val && x != 101);//encoding
	x=0;
	do 
	{
		printf("%c", line[x]);
		x++;
	}while (line[x] != val && x != 101);
	puts("");//printing
}

void encode_file()
{
//not done
}

main ()
{
	int use;
	location1: ;
		puts("What do you want to do?");
		scanf("%d", &use);
		if (use == 1) decode_line();//if you don't understand you are an- id ten t
		if (use == 2) decode_file();//if you don't understand you are an- id ten t
		if (use == 3) encode_line();//if you don't understand you are an- id ten t
		if (use == 4) encode_file();//if you don't understand you are an- id ten t
		if (use == 5) return 0;//quit
		if (use != 1 && use != 2 && use != 3 && use != 4 && use != 5 )
		{//print menu
			puts("1 to decode a line");
			puts("2 to decode a file");
			puts("3 to encode a line");
			puts("4 to encode a file");
			puts("5 to quit");
		}
	
		scanf("%c");//clear any charachers after printing menu
		goto location1;
	return 0;
}






