Thread: h/w help

  1. #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..

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    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;
    }

  3. #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

  4. #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

  5. #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

  6. #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?

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    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]

  8. #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

  9. #9
    Registered User
    Join Date
    Jul 2003
    Posts
    61
    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

  10. #10
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Read the last sentence in Hammer's post:

    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

  11. #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

  12. #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.

  13. #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 #.

  14. #14
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    Hope is the first step on the road to disappointment.

  15. #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;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick H/W question...
    By djz3r0 in forum C++ Programming
    Replies: 15
    Last Post: 09-12-2004, 08:36 PM