So i want to learn new things. My idea for text encryption is to increase the ascii value of a char in a char pointer of its index like char[1] will increase the ascii number by 2 because its the 2nd element. If the ascii number is bigger than 90 (Z) it starts from 65 (A) and continues increasing (its for capital letters only). When the index is bigger than 26 it will probably decrease number i increase the chars but it doesnt matter. I have to fix this code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int *encrypt(char *src, char *dst) {
for(int i=0; i<=strlen(src); i++) {
for(int j=i+1; j>0; j--) {
if(src[i] < 65 || src[i] > 90) {
dst[i] = ' ';
break;
} else
dst[i] = src[i];
if(dst[i] == 90)
dst[i] = 65;
else
dst[i] ++;
}
}
return 0;
}
int main(int argc, char *argv[]) {
char *src, *dst = malloc(256);
fgets(src, 255, stdin);
encrypt(src, dst);
printf("%s", dst);
return 0;
}```
My problem is that in the encrypt function all characters increase by 1 only. Im not sure why, the loop executes multiple times however every letter become increased by one after the function finishes which isnt what i expect.