Hello, i recently saw the film The Prestige, and one of the actors keeps a diary, and writes in it using a keyword cipher. I decided to make a program that when i input text it outputs the text in the cipher (switches one letter for another letter).
I think i have written my function declaration wrong, and when im calling the function i think i've done it wrong, and when i prototype it i think i've done it wrong.
Also, how do i assign 'x' to the number that the array is on?
'x' needs to be initialised, but i am not sure how i initialize it to this position?
Take a look at the code to understand what i mean.
Thanks in advance to anyone who can help me out
Code:
#include <stdio.h>
void fConvert(int, char[]);
int main(void)
{
char cText[100];
int x;
printf("Enter text:");
fgets(cText, 100, stdin);
if(cText[x] != '\0')
{
fConvert(x, cText);
}
return 0;
}
void fConvert(int a, char b[100])
{
for(a; b[a]!='\0'; a++)
{
switch(b[a])
{
case 'a':
printf("t");
break;
case 'b':
printf("e");
break;
case 'c':
printf("s");
break;
case 'd':
printf("l");
break;
case 'e':
printf("a");
break;
case 'f':
printf("b");
break;
case 'g':
printf("c");
break;
case 'h':
printf("d");
break;
case 'i':
printf("f");
break;
case 'j':
printf("g");
break;
case 'k':
printf("h");
break;
case 'l':
printf("i");
break;
case 'm':
printf("j");
break;
case 'n':
printf("k");
break;
case 'o':
printf("m");
break;
case 'p':
printf("n");
break;
case 'q':
printf("o");
break;
case 'r':
printf("p");
break;
case 's':
printf("q");
break;
case 't':
printf("r");
break;
case 'u':
printf("u");
break;
case 'v':
printf("v");
break;
case 'w':
printf("w");
break;
case 'x':
printf("x");
break;
case 'y':
printf("y");
break;
case 'z':
printf("z");
break;
default:
printf("Error, was not a letter");
break;
}
}
}