"Piotr Turkowski" <pi***@ust.tke.pl> wrote in message
news:c2**********@nemesis.news.tpi.pl...
Hi,
The code is here: http://free.ud.pl/~piotr/data/vigenere.zip
Its my program for decrypting and encrypting text.
Shot polish course:
szyfrowanie (szyfruj) - encrypting (text i want to code ->
(*(^%&^GHJBBVvkek)
odszyfrowanie (deszyfrowanie) - decrypting ( *^BNHJ*&% - > secret text)
obsluga plikow - using files
If you delete case 4 (obsługę plików) from the menu and the bad function
the program will work.
This is the problem. I don't know how to use files. I want to make a
function in which you will enter a path for incoming file and outgoing
file.
There are 4 possibilities:
1) you have entered both paths, the program will encrypt or decrypt text
from file_in to file_out
2) you have enetered path for file_in, the text will be encrypted or
decrypted and showed on display
3) you have entered path for file_out, the text will be taken from
keyboard and writted into file_out
4) no paths, the text will be got form keyboard and showed on display
In this function first I want to check if paths are correct.
If you understood me, please help me with this. I'm tired of this.
Well you do have a problem here...
You have...
void szyfruj(){
int ii, c, i, s, p, npass, nnpass;
char *pass;
char ALPHA[94][94]={0};
wypelnij_tab(ALPHA);
printf("Podaj haslo: ");
gets(pass);
for (npass=0; pass[npass] != '\0';++npass); /* liczenie ilosci znakow */
....
}
Notice there is no storage allocated for 'pass'. Your code is crawling with this
error. Some compilers will let you get away with this so I can get...
/*
1. Szyfrowanie tekstu.
2. Deszyfrowanie tekstu.
3. Statystyka.
4. Obsluga plikow.
5. Zakonczenie programu.
Menu: 1
Podaj haslo: abc
Podaj tekst do zaszyfrowania:
Hello
+IQOS
*/
Others have commented on your 'overkill'. I take that to mean 'overly
complicated'.
Consider...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
enum DIR {EN, DE};
const char START = ' ', END = '~';
void cipher (const enum DIR);
int main (void) {
/* menu programu */
int menu;
for (;;) {
printf ("\n");
printf ("1. Szyfrowanie tekstu.\n");
printf ("2. Deszyfrowanie tekstu.\n");
printf ("3. Zakonczenie programu.\n");
printf ("\n\tMenu: ");
scanf ("%d", &menu);
getchar ();
switch (menu) {
case 1:
cypher (EN); /* ENcode */
break;
case 2:
cypher (DE); /* DEcode */
break;
case 3:
return 0;
default:
break;
}
}
}
void cipher (const enum DIR d) {
const int len = END - START, pos = d ? len : 0;
char pass[40], *p;
int c;
printf ("Podaj haslo: ");
fgets (pass, sizeof pass, stdin);
/* May include a newline ('\n') */
p = strchr (pass, '\n');
if (p)
/* Lose the newline ('\n') */
*p = '\0';
p = pass;
printf ("Podaj tekst:\n");
while ((c = getchar ()) != '\n')
if (c >= START && c <= END) {
const int i = pos - *p + START;
printf ("%c", (abs (i) + c - START) % len + START);
if (!*++p)
p = pass;
}
else
printf ("%c", c);
putchar ('\n');
}
/*
1. Szyfrowanie tekstu.
2. Deszyfrowanie tekstu.
3. Zakonczenie programu.
Menu: 1
Podaj haslo: abc
Podaj tekst:
Hello
+IQOS
1. Szyfrowanie tekstu.
2. Deszyfrowanie tekstu.
3. Zakonczenie programu.
Menu: 2
Podaj haslo: abc
Podaj tekst:
+IQOS
Hello
*/
Pardon my Polish!
Regards
Brian