Extra printed stmts...why?

This is a discussion on Extra printed stmts...why? within the C Programming forums, part of the General Programming Boards category; This is a program that encrypts & then decrypts a given string - there should be only 3 printed statements ...

Extra printed stmts...why?

This is a program that encrypts & then decrypts a given string - there should be only 3 printed statements (plaintext, encrypted text & decrypted text)...(never mind it's not formatted to not overflow on the screen, I'll deal with that later)

Here's the problem:
I'm getting 5 printed statements & I can't see the reason why...
This may be something really obvious but I'm at a loss (first semester C prog student)

...if anybody can shed some light on this I would really appreciate it!

int main(void)
{
const char plaintext[] = "Fourscore and seven years ago our fathers \
brought forth upon this continent a new nation, conceived in liberty, \
and dedicated to the proposition that all men are created equal.";

You call printtext three times. This is the regular output that you see. You also call encrypt and decrypt each once. The encrypt and decrypt functions do not actually change the data, but instead loop through the string and output the encrypted or decrypted character to the screen using the putchar(). This is why there are five outputs: three regular, one encrypted, one decrypted.

printing stmts...

Thanks David -
now it makes sense as to 'why' I'm getting the extra statements but I'm confused on how to eliminate this problem - if I don't use putchar() in the switch statements how else can I transfer the values of each character (I originally had printf() in the switch stmt but I think that was producing the same output)

int main(void)
{
const char plaintext[] = "Fourscore and seven years ago our fathers \
brought forth upon this continent a new nation, conceived in liberty, \
and dedicated to the proposition that all men are created equal.";

Sorry I wasn't able to get back to you again yesterday, but it looks like swoopy has already posted a solution. Basically, after a few adjustments to the way the functions are handled, you just want to return the appropriate value to be assigned into the array instead of outputting to the screen.