recursion - Recursive transposition cipher C -


i trying intake string of chars , split them recursively in half until char length 2. take char string of 2 , swap char string next it. code below:

#include <stdio.h> #include <string.h>  void encrypt(char *str, int size);  int main(){     char input[8192];     int length;      printf("input phrase: ");     fgets(input, 8192, stdin);     length = strlen(input) -1;     printf("length: %d\n", length);      encrypt(input, length);     printf("encryption: %s\n", input);       return 0; }  void encrypt(char str[], int size){     int i;     int k = size / 2;      //encryption code here  } 

some example outputs:

sample input: 12345678  sample output: 34127856  sample input: test , often!  sample output: aeyrlet sttf!enn aod 

i'm not asking assignments me. looking nudge in right direction having tough time wrapping head around how continuously split string swap.

op: "i'm not asking assignments me. looking nudge in right direction"

the recursive code needs split string , careful length, odd or even.

void encrypt(char str[], int size){    if (size <= 2) {     // encryption, tbd code     retrun;   }    int i;   int k = size / 2;  //  step 1    char *left = ____; // address of left half?  (easy)    // call encrypt of left half   encrypt(left, ___); // size of left half? (easy)    // right   char *right = ____; // address of r half?                        // (hint, begins @ left half end.)    // r half length (hint: total - ???)   // call encrypt again r half , length   encrypt(right, ___);  } 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -