Hey everyone, I'm writing a program for a class. It's a relatively simple C program that I'm compiling in Dev C++. I'm trying to make it as complex as possible, but I'm just a college freshman and don't know much beyond the basics of programming.
I'd like to enable option to have the user select an input file and output file for the text to be encoded and decoded, as well as an option of which substitution cypher to use (26 in total). I'm a total noob when it comes to file I/O, but here's my code so far. Any tips/recommendations are very much appriciated!
#include "stdio.h"
#include "stdlib.h"
#define ESC 27 /* standard ascii value for the escape key */
int main()
{
int i=0; // declare a variable named i of type int
char ch=0; // declare a variable named ch of type char
char *alpha="abcdefghijklmnopqrstuvwxyz"; // declare a char pointer to the beginning of the alphabet
char *key="zyxwvutsrqponmlkjihgfedcba"; // declare a char pointer to the beginning of the key
// FILE *infile, *outfile;
// infile=fopen("quad.dat", "r+");
system("cls");
printf("Cryptology Tool Prototype\n");
while(ch!=ESC) // do the following while the escape character is not present
{
printf("Type the message you would like to encode\n");
ch=fgetc(stdin); // store a character entered from standard input into ch
if(isalpha(ch)) // do the following if ch is a letter
{
for(i=0;i<26;i++) // for(INIT ; LOOP WHILE THIS IS TRUE ; MANIPULATE)
{
if(alpha[i]==tolower(ch)) // if the character residing at alpha + offset i = ch
{
ch=(isupper(ch)) ? (toupper(key[i])):key[i];
printf("%i\n");
break;
} // end of if
} // end of for
} // end of if
fputc(ch,stdout);
} // end of while
return(0);
} // end of main