Thanks for the pastied code. Using TCC on WinXP, I also get
an extra character, in my case a 'V'.
I replaced your 'while' block with this:
while((c = getchar()) != EOF)
{
printf("\nc=%i\n", c); /* line added for debugging */
putchar(encode((char) c,
argv[2][key_count%key_length]));
key_count++ ;
}
Copied from the command line window:
> tcc -Wall -run test.c -encode HELLO
MORNING
c=77
3
c=79
2
c=82
C
c=78
8
c=73
6
c=78
4
c=71
U
c=10
V^C
>
(The ^C is me pushing ctrl-C to stop the program.)
The extra character is due to c == 10: this is 0x0A, or
ASCII LF.
Quick and dirty fix:
while(c = getchar())
{
if (c == 0x0A)
break;
putchar(encode((char) c,
argv[2][key_count%key_length]));
key_count++ ;
}
Which gives:
> tcc -Wall -run test.c -encode HELLO
MORNING
32C864U
>
This fix may differ according to your setup and probably
isn't portable.
Have a good look at the documentation for getchar() as
that's where you problem lies. Also, character-by-character
keyboard input is notorious for buffering problems.
David