I have to write a code for the caesar cipher where you enter whether you want to decrypt or encrypt and then enter the key for how many spaces you want the characters to shift and then it will show the result. The only requirements is that I have to include these two lines of code "void caesar_encrypt(char src[], int key, char dist[])" and "void caesar_decrypt(char src[], int key, char dist[])". I am stuck. I am not sure what to do with the char dist[] part and I cannot get the functions to work correctly. Any help would be appreciated. Here is what I have so far and the errors .On lines 49 and 53 the errors are the same for both lines which is "invalid conversion from 'char' to 'char*'" and "initializing argument 1 of 'void caesar_encrypt(char*, int)'" except for the other error says "void caesar_decrypt" instead.
1- the return; in ur functions make no sense because return must be followed by ...something. Also, those funcs are declared as 'void' which means it doesnt return anything.
2-caesar_decrypt(src[100], key);
u'r only sending in 1 element of the array and not the entire array as i think u want.
3-The
"invalid conversion from 'char' to 'char*'"
comes from trying to send in 1 element, src[100], into a func that takes a pointer to an array. void caesar_encrypt(char src[100], int key) is declaring a char array called scr of size 100 exactly the same way that u originally defined it on line 27...
4 -to fix this issue all u have to do is declare ur funcs to accept a pointer to the whole array ie char src[]. When u pass in ur array u simply want to pass in its pointer which is simply caesar_encrypt(src, key);
5-The encryption and decription have to be done basically like u did but in a loop for each element of the array. U should also add a delimiter to know the size of the array so that u don't encrypt more letters than those that were input.
U'r not getting any result because the variable set on line 40 never changes so lines 7 and 20: for (int i=0; i<dist; i++) end up like this for(int i=0; i<-1; i++) which of course is never true.
U need to assign 'dist' to be the actual length of the user's input.
Also for design, asking for a lower case 'encrypt/decrypt' operation and then expecting upper case letters for the actual text without informing the user is a little confusing. Ideally u'd accept either as the input text and convert it all to either upper case or lower case.