Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
char array[20];
int length = 0;
int i;
int key = 256;
printf("input: ");
fgets(array, 20, stdin);
length = strlen(array) - 1;
key = key % length;
if (key > 0) {
for (i = 0; i < length; i++) {
if (array[i] == ' ') {
printf("%c", array[i]);
continue;
}
array[i] = array[i] + key;
printf("%c", array[i]);
}
}
return 0;
}
so this code gets user input string
then 256 mod input length will be calculated. if the result is 3 all letters will be shifted by three. however when the input is something like this "hey whatsup" the length should be 10 and not 11. the space get's counted aswell.
I am trying to tell the program not to add spaces to the input length. But it should print out the space , which i managed to implement.
I can't seem to figure out how to tell fgets to remove spaces from the length.