Hello i am fairly new to programming in C and basically the decrypt array only holds the first value entered into in below is my code also any tips to help me improve are appreciated;
int main(int argc, char *argv[]) {
char input[100] = "";
char target[100] = "";
char replace[100] = "";
char keycipher[100] = "";
int i, size;
static char decrypt[100] = "";
while(1){
printf("\nEnter Target: ");
fgets(target, 17, stdin);
printf("Replace With: ");
fgets(replace, 17, stdin);
for(i = 0; i < size; i++)
{
if(input[i] == target[0]) {
decrypt[i] = target[i];<-this is where it is supposed to be added
input[i] = replace[0];
printf("\n%s",input);
printf("\n%s",decrypt);
}
}
if(target[0] == 'q' || replace[0] == 'q'){
break;
}
}
printf("decryt @# %s", decrypt);
printf("\nDecrypting .....\n");
printf("Your orginal string was: ");
for(i = 0; i < 100; i++)
{
input[i] = decrypt[i];
printf("%s", input);
}
printf("\nSIMULATION OVER!\n");
system("PAUSE");
return 0;
}
the output i receive is as follows;
*--------------------------*
| Welcome to the Scrambler |
*--------------------------*
Remember press q to quit
Please enter a string: hello stranger
you entered: hello stranger
Enter target: h
Replace with: w
wello stranger
decrypt array: h
Enter target: s
Replace with: p
wello ptranger
decrypt array: h <-------- why is this still just h?
Enter target: q
Replace with:
decrypt holds: h <----------
Decrypting .....
Your original string was: hello ptrangerhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
SIMULATION OVER!
also how can i check if the target is already in the array so they can`t add that character?