Code:else if (input = 'I') fputs("@#", stdout); etc...
Code:else if (input = 'I') fputs("@#", stdout); etc...
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
the code works but its still the same problem.
it subsitutes the vowels with a #, on the the other hand each vowel is required to have its own subsitute.
ie
user enters as i
out put #s %
any ideas on how to do this?
Look at your if check. See the problem?
This assigns 'a' to 'foo'. Try it with two equal signs.Code:if( foo = 'a' )
= assigns
== checks equality
Quzah.
Hope is the first step on the road to disappointment.
It worked
Whats confusing is that the output for the first series of characters is not working correctly if you start it with 'a'
sample output
all i need in life i c
Encryted Text Below...
ll @ n%%d @n l@f% @ c
As you can see, the character that is to be in the place of 'a' is missing. If i enter the same sentence again, without exiting the program then it will correctly display.
Code:#include "stdio.h" #include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { int input; printf("\nEnter text to encypt...\n"); getchar(); printf("\n\nEncryted Text Below...\n"); do{ input = getchar(); // if a character is equivalent to a vowl. it will be repalced with what it is == to. if(input != 'a' && input != 'i' && input != 'o' && input != 'u' && input != 'e' && input != 'A' && input != 'I' && input != 'O' && input != 'U' && input != 'E') fputc(input,stdout); else if (input == 'a') fputs("!", stdout); else if (input == 'i') fputs("@", stdout); else if (input == 'o') fputs("#", stdout); else if (input == 'u') fputs("$", stdout); else if (input == 'e') fputs("%", stdout); else if (input == 'A') fputs("^", stdout); else if (input == 'I') fputs("@#", stdout); else if (input == 'O') fputs("@#", stdout); else if (input == 'U') fputs("^%^", stdout); else if (input == 'E') fputs("%$@", stdout); } while(input != '0'); // check to make sure user has input return 0; }
it's because of the extra call to getchar():
one solution I can think of is using ungetc, something like this:Code:printf("\nEnter text to encypt...\n"); getchar(); // here printf("\n\nEncryted Text Below...\n");
Code:printf("\nEnter text to encypt...\n"); input = getchar(); printf("\n\nEncryted Text Below...\n"); ungetc( input , stdin );
Yuk! Change the first getchar() to fgets() to read the entire line in all at once into a buffer.Originally posted by glUser3f
...
one solution I can think of is using ungetc, ...
Then in the while loop, simply look at each character in the buffer.
And if you know the switch statement, use that instead of all the if statements. If not, get rid of the HUGE if statement and put the fputc(input,stdout); at the end of your if-block:
Code:else if (input == 'O') fputs("@#", stdout); else if (input == 'U') fputs("^%^", stdout); else if (input == 'E') fputs("%$@", stdout); else fputc(input,stdout); // If no if above got called, do not translate
Last edited by WaltP; 10-21-2003 at 09:38 AM.
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers