![]() |
| | #1 |
| Registered User Join Date: Oct 2003
Posts: 12
| I spent about 4 hours and im stuck on one aspect of the program that i am writing .. its a h/w assignment ![]() so this is the problem, i need to find a way to tell the user to enert 10 character - thats easy. heres the hard part - or thats what i thinnk is hard the program must scan the input for several letters, then subsiture other letters in thier place. lets say the user enter abchdish ui the program would replace the letter a with lets say # so the output would be #bchdish ui thanks.. |
| helpme is offline | |
| | #2 |
| Registered User Join Date: May 2002 Location: Cape Town
Posts: 777
| You should be able to work your way through this code. Unfortunately, it uses conio.h which is not an ANSI standard header. Code: #include <stdio.h>
#include <conio.h> //Not ANSI compliant
int main( void )
{
int input;
do{
input = getch();
if( input != 'a' )
fputc( input, stdout );
else
fputc( '#', stdout );
}while( input != '0' );
return 0;
}
|
| The Dog is offline | |
| | #3 |
| Registered User Join Date: Oct 2003
Posts: 12
| thanks.... the problem is that we have to use ANSI. Im taking a look at the code to see if i can implement it |
| helpme is offline | |
| | #4 |
| Registered User Join Date: Jul 2003
Posts: 61
| Not sure, if that's what you want, but here the ansi version: Code: #include <stdio.h>
int main( void )
{
int input;
do{
input = getchar();
if( input != 'a' )
fputc(input,stdout);
else
fputc('#' stdout);
}while( input != '0' );
return 0;
}
__________________ $ENV: FreeBSD, gcc, emacs |
| cc0d3r is offline | |
| | #5 |
| Registered User Join Date: Feb 2002
Posts: 236
| Whatever happened to "Post what you have so far....." ?
__________________ Demonographic rhinology is not the only possible outcome, but why take the chance |
| Azuth is offline | |
| | #6 |
| Registered User Join Date: Oct 2003
Posts: 12
| updates It seems that when i try to run the code that was given in ANSI above i get a " fatal error C1010: unexpected end of file while looking for precompiled header directive" anyone knows what that means? |
| helpme is offline | |
| | #7 |
| End Of Line Join Date: Apr 2002
Posts: 6,240
| I assume you're using MSVC6. Turn off precompiled headers in the project options. There's been plenty of threads on this before, try searching for one if you get stuck.
__________________ When all else fails, read the instructions. If you're posting code, use code tags: [code] /* insert code here */ [/code] |
| Hammer is offline | |
| | #8 |
| Registered User Join Date: Oct 2003
Posts: 12
| thanks for the info.. but i have one question how do i do that ![]() im new with c so i hope that you guys would cope with me |
| helpme is offline | |
| | #9 | |
| Registered User Join Date: Jul 2003
Posts: 61
| Quote:
__________________ $ENV: FreeBSD, gcc, emacs | |
| cc0d3r is offline | |
| | #10 | |
| C++ Developer Join Date: Jun 2002 Location: UWaterloo
Posts: 2,718
| Read the last sentence in Hammer's post: Quote:
__________________ 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 | |
| XSquared is offline | |
| | #11 |
| Registered User Join Date: Jul 2003
Posts: 61
| So is he having a problem with searching the board or turning of precompiled headers?
__________________ $ENV: FreeBSD, gcc, emacs |
| cc0d3r is offline | |
| | #12 |
| Registered User Join Date: Oct 2003
Posts: 12
| updates prblem solved . i was getting the error since i copied and paste the code.. i manually entered the code and the program ran fine thanks Last edited by helpme; 10-19-2003 at 09:07 PM. |
| helpme is offline | |
| | #13 |
| Registered User Join Date: Oct 2003
Posts: 12
| i figured out how to make it edit more than one character. what i am stuck on now, is to assign differnt character different symbols. lets for a , we will have # and for b. we will have $ i reached a stage where all the charcters sepcified will have the same symbol placed for them, so a and b will have #. |
| helpme is offline | |
| | #14 | |
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 10,640
| Quote:
Code: if( foo == 'a' )
... put replacement character
else
if( foo == 'b' )
... put replacement character
...lather, rinse, repeat...
Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? | |
| quzah is offline | |
| | #15 |
| Registered User Join Date: Oct 2003
Posts: 12
| code As you can see from the code below, AIOUEaioue are all converted to #. Is it possable so that 'a' will be converted to foo while 'i' is converted to fooffooo ? as you can see my if looops are missing something... any suggestions? Code: // hardcoder.cpp : Defines the entry point for the console application.
//
#include "stdio.h"
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
int input
getchar();
do{
input = getchar();
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')
fputc('#', stdout);
else if (input = 'i')
fputc('@', stdout);
else if (input = 'o')
fputc('#', stdout);
else if (input = 'u')
fputc('$', stdout);
else if (input = 'e')
fputc('%', stdout);
else if (input = 'A')
fputc('^', stdout);
else if (input = 'I')
fputc('@#', stdout);
else if (input = 'O')
fputc('@#', stdout);
else if (input = 'U')
fputc('^%^', stdout);
else if (input = 'E')
fputc('%$@', stdout);
}
while(input != '0');
return 0;
}
|
| helpme is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Quick H/W question... | djz3r0 | C++ Programming | 15 | 09-12-2004 08:36 PM |