Re: simple encryption

Bill Cunningham <nospam@xxxxxxxxxxxxx> wrote:
Somehow I am going to have to integrate the flip function into main. Len
from the second parameter to flip might be able to be altered to take a call
to malloc or strlen. But main is going to have to be altered significantly.

You want to call flip() on the buffer you read in, right? The buffer,
as you have it, is only one character long, and is stored in the int a.
Things are a little funky because getc() returns an int, but if it's not
EOF, it's the next character, an unsigned char. So here I assign it
into an unsigned char, and then pass a pointer to that to flip():

[All code untested.]

while ((a = getc(fp)) != EOF) {
unsigned char c = a;
flip(&c, 1);
putc(c, stdout);

Or you can read into a string and skip a lot of that nonsense--it's way
more efficient, too:
char buffer[1024];
while (fgets(buffer, sizeof buffer, stdin) != NULL) {
flip(buffer, strlen(buffer));
fputs(buffer, stdout);

But I warn ya: the stuff that goes to stdout is going to be pretty