C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-19-2003, 09:45 AM   #1
Registered User
 
Join Date: Oct 2003
Posts: 12
Angry h/w help

Hi,

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   Reply With Quote
Old 10-19-2003, 10:08 AM   #2
Registered User
 
The Dog's Avatar
 
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   Reply With Quote
Old 10-19-2003, 10:37 AM   #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   Reply With Quote
Old 10-19-2003, 11:15 AM   #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;
}
HTH,
__________________
$ENV: FreeBSD, gcc, emacs
cc0d3r is offline   Reply With Quote
Old 10-19-2003, 04:41 PM   #5
Registered User
 
Azuth's Avatar
 
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   Reply With Quote
Old 10-19-2003, 05:03 PM   #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   Reply With Quote
Old 10-19-2003, 05:08 PM   #7
End Of Line
 
Hammer's Avatar
 
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   Reply With Quote
Old 10-19-2003, 05:41 PM   #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   Reply With Quote
Old 10-19-2003, 07:07 PM   #9
Registered User
 
Join Date: Jul 2003
Posts: 61
Quote:
Originally posted by helpme
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
Exactly _what_ are trying to do ??
__________________
$ENV: FreeBSD, gcc, emacs
cc0d3r is offline   Reply With Quote
Old 10-19-2003, 07:08 PM   #10
C++ Developer
 
XSquared's Avatar
 
Join Date: Jun 2002
Location: UWaterloo
Posts: 2,718
Read the last sentence in Hammer's post:

Quote:
There's been plenty of threads on this before, try searching for one if you get stuck.
__________________
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   Reply With Quote
Old 10-19-2003, 07:32 PM   #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   Reply With Quote
Old 10-19-2003, 07:40 PM   #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   Reply With Quote
Old 10-20-2003, 04:30 PM   #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   Reply With Quote
Old 10-20-2003, 07:22 PM   #14
+++ OK NO CARRIER
 
quzah's Avatar
 
Join Date: Oct 2001
Posts: 10,640
Quote:
Originally posted by helpme
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 #.
Well you could do as someone suggested, oh, and the rules tell you, and post your code so far. But since no one ever actually follows the forum rules, do something like this:
Code:
if( foo == 'a' )
    ... put replacement character
else
if( foo == 'b' )
    ... put replacement character
...lather, rinse, repeat...
Or you could do a lookup table using an array or what not, and do it that way.

Quzah.
__________________
Hundreds of thousands of dipshits can't be wrong.


Are you up for the suck?
quzah is offline   Reply With Quote
Old 10-20-2003, 08:07 PM   #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   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Quick H/W question... djz3r0 C++ Programming 15 09-12-2004 08:36 PM


All times are GMT -6. The time now is 12:04 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22