Re: Vigenere Cipher II - how to use files
From: Mike Wahler (mkwahler_at_mkwahler.net)
Date: 03/03/04
- Next message: Mike Wahler: "Re: memory accesses"
- Previous message: Adi: "memory accesses"
- In reply to: Piotr Turkowski: "Vigenere Cipher II - how to use files"
- Next in thread: David Rubin: "Re: Vigenere Cipher II - how to use files"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 02 Mar 2004 23:42:17 GMT
"Piotr Turkowski" <piotr@ust.tke.pl> wrote in message
news:c234df$j5l$1@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 (obsluge 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.
Where's your texbook? :-)
>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
I'd probably approach it something like this
(not compiled or tested):
#include <stdio.h>
void func(const char *in_path, /* Pass NULL for stdin */
const char *out_path) /* Pass NULL for stdout */
{
FILE *in = in_path ? fopen(in_path, "r") : stdin;
FILE *out = out_path ? fopen(out_path, "w") : stdout;
if(in && out)
{
/* do your stuff */
if(in && in != stdin)
fclose(in);
if(out && out != stdout)
fclose(out);
}
else
{
/* could not open either input, output, or both.
Handle error. */
}
}
void callit(void)
{
func("inputpath", "outputpath"); /* case 1) */
func("inputpath", NULL); /* case 2) */
func(NULL, "outputpath"); /* case 3) */
func(NULL, NULL); /* case 4) */
}
Another possibility is to use an 'emtpy string' ("")
instead of NULL to indicate stdin and stdout, but
the idea is the same.
>
> In this function first I want to check if paths are correct.
"Correctness" of a 'path name' is in the domain of your
operating system, so you'll need to check your documentation.
If by "correct" you mean does e.g. the input file exist
or the output file not exist, See the documentation for
the 'open mode' (second argument) of 'fopen()'. 'fopen()'
returns a NULL pointer upon failure, a non-NULL pointer
upon success. 'stdin' and 'stdout' are automatically
'open' at program startup (and don't try to close them! :-)).
>
> If you understood me, please help me with this. I'm tired of this.
>
> BTW:
> How to enter a password, and show stars(*) on screen ?
Not possible with standard C. Perhaps your implementation
provides an extension for this. Consult your documentation.
> How to make a decision in a menu without confirming it by enter?
Same answer as to the the first 'BTW' question.
HTH,
-Mike
- Next message: Mike Wahler: "Re: memory accesses"
- Previous message: Adi: "memory accesses"
- In reply to: Piotr Turkowski: "Vigenere Cipher II - how to use files"
- Next in thread: David Rubin: "Re: Vigenere Cipher II - how to use files"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|