C
Carl Harris
I am trying to write some code to:
1.Prompt a user for filenames
2.Open the files
3.Convert my plain text into a cipher text array/string
bear in mind I am a novice!
I have wriiten some code already which completes takes 1 and 2 but
haven't got a clue with the conversion (task 3)
The key (infile)file would contain: WGHMSAZIQRTBVCYPDJEKXFLNUO
so therefore W=A, G=B,.......O=Z
The plaintextfile would contain the text to be converted.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
void main()
{
FILE *Key;
char c;
char infile[100];
printf("\n Input infile name:");
gets(infile);
printf("The Key is: \n");
if ((Key=fopen(infile,"r"))== NULL)
{
printf("can't open infile");
exit(0);
}
else {
do {
c = getc(Key); /* get one character from the file */
putchar(c); /* display it on the monitor */
} while (c != EOF); /* repeat until EOF (end of file) */
printf("\n");
}
fclose(Key);
FILE *text;
char d;
char plaintextfile[100];
printf("\n Input plain text file name:");
gets(plaintextfile);
if ((text=fopen(plaintextfile,"r"))== NULL)
{
printf("can't open plain text file");
exit(0);
printf("The plain text is: \n");
}
else {
do {
d= getc(text); /* get one character from the file */
putchar(d); /* display it on the monitor */
} while (d != EOF); /* repeat until EOF (end of file) */
printf("\n");
}
fclose(text);
*/HERE IS WHERE I AM GOING WRONG*///////////////*
char a[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int ciphertext;
putchar(ciphertext);
printf("The ciphertext is: \n");
}
1.Prompt a user for filenames
2.Open the files
3.Convert my plain text into a cipher text array/string
bear in mind I am a novice!
I have wriiten some code already which completes takes 1 and 2 but
haven't got a clue with the conversion (task 3)
The key (infile)file would contain: WGHMSAZIQRTBVCYPDJEKXFLNUO
so therefore W=A, G=B,.......O=Z
The plaintextfile would contain the text to be converted.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
void main()
{
FILE *Key;
char c;
char infile[100];
printf("\n Input infile name:");
gets(infile);
printf("The Key is: \n");
if ((Key=fopen(infile,"r"))== NULL)
{
printf("can't open infile");
exit(0);
}
else {
do {
c = getc(Key); /* get one character from the file */
putchar(c); /* display it on the monitor */
} while (c != EOF); /* repeat until EOF (end of file) */
printf("\n");
}
fclose(Key);
FILE *text;
char d;
char plaintextfile[100];
printf("\n Input plain text file name:");
gets(plaintextfile);
if ((text=fopen(plaintextfile,"r"))== NULL)
{
printf("can't open plain text file");
exit(0);
printf("The plain text is: \n");
}
else {
do {
d= getc(text); /* get one character from the file */
putchar(d); /* display it on the monitor */
} while (d != EOF); /* repeat until EOF (end of file) */
printf("\n");
}
fclose(text);
*/HERE IS WHERE I AM GOING WRONG*///////////////*
char a[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int ciphertext;
putchar(ciphertext);
printf("The ciphertext is: \n");
}