So I created algorithm that ciphers a string for my classes. Its supposed to use Caesars cipher, and there is 2nd algorithm that decyphers. The algoritym looks like that
#include <stdio.h>
#include <string.h>
#define N 1001
#define k 4
int szyfrowanie(); //cipher function
int deszyfrowanie(); //decipher function
int main()
{
printf("Chcesz szyfrowac(1) czy deszyfrowac(2)?"); //user can choose to cipher or decip
int wybor; //"choice"
scanf("%d", &wybor);
if(wybor == 1)
szyfrowanie();
else
deszyfrowanie();
return 0;
}
szyfrowanie()
{
char *tab[N];
printf("Podaj ciag do zaszyfrowania: "); //user inputs string to cipher
fgets(tab, sizeof(tab), stdin); //user input
printf("zaszyfrowany ciag znakow to: "); // "ciphered string is"
int i; //zmienna sterujaca
int dl = strlen(tab); //pobieramy dlugosc stringa wpisanego przez uzytkownika zeby nie zrobic za duzo iteracji :)
for (i = 0; i < dl; i++) //petla "zaszyfruje" nam nasz string
{
tab[i] = tab[i] + k; //sam proces szyfrowania
}
puts(tab); //wypisanie zaszyfrowanego stringa
return 0;
}
deszyfrowanie() //decipher function
{
char *tab[N];
printf("Podaj ciag do zdeszyfrowania: "); //uzytkownik podaje zdanie do zdeszyfrowania
fgets(tab, sizeof(tab), stdin); //wejscie uzytkownika
printf("zdeszyfrowany ciag znakow to: ");
int i; //zmienna sterujaca
int dl = strlen(tab); //pobieramy dlugosc stringa wpisanego przez uzytkownika zeby nie zrobic za duzo iteracji :)
for (i = 0; i < dl; i++) //petla "zdeszyfruje" nam nasz string
{
tab[i] = tab[i] - k; //sam proces deszyfrowania
}
puts(tab); //wypisanie zdeszyfrowanego stringa
return 0;
}
(I've made some comments for you to understand since code is in polish ^^)
So the problem is that if I compile this code, user can choose to cipher and decipher but then he cant input the string, the program acts like the string is just empty and finishes work with no output
If I just put a cipher algorithm into the main function it works like a charm. Whats The problem?