Thread: help with design question...

  1. #1
    Learner Axel's Avatar
    Join Date
    Aug 2005
    Posts
    335

    help with design question...

    ok for example i have a getInput(char string[]) method i pass a char array it then uses fgets to repetively ask for input till a special key is entered.

    Once something is inputted i then go and do some calculations to it the method is scrabble(char string[]) this is all done in the same getInput method. I have to do the method calls in this because it determines if the program should continue or exit.

    What i would like to achieve have all the function calls in main() rather than dropping them inside the bottom functions.


    so

    Code:
    int main()
    {
         getInput()....
         scrabble().....
    }
    the problem is i have the repetiveness of the task. It's ok to do the above if i were to ask for one input....hmm any ideas? it's a bit confusing, i hope it's clear enough.

    so i want to get the input, run scrabble in main. but since i have to return to get input again i'm not sure what to do (without dumping a bunch of fget calls in main())
    Last edited by Axel; 09-16-2006 at 08:07 AM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    No it's not OK to do the above. Learn to use code tags. You have nearly 250 posts, so you have no excuse!
    USE CODE TAGS!
    I don't care if it's some stupid little example. If it should be indented, wrap it in tags!


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Learner Axel's Avatar
    Join Date
    Aug 2005
    Posts
    335
    yes the code was intended to be read inline with the background information, i thought it should be reserved for real code.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Why? To make it annoying to read "fake code"? Here's a hint: HELP PEOPLE WANT TO HELP YOU! God damnit! Why can't people get it through their heads that they should be helpful to people they're asking for help from? Alright, I don't care any more. I'll just put your ass on ignore. I'm tired of people not using code tags. No tags = an ignore from me from now on. And I don't mean I'm just not going to read your ......... I mean I'm adding all of you ass hats to my ignore list.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Learner Axel's Avatar
    Join Date
    Aug 2005
    Posts
    335
    hmm having a bad day? I've corrected the coding tags. As i already said the code actually should of really been included in the sentence so that it coincided with what i was actually trying to explain and usually when code tags are used most people think it's actual real code. Regardless i think i'll use code tags next time.

  6. #6
    Learner Axel's Avatar
    Join Date
    Aug 2005
    Posts
    335
    here's what i mean:

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    
    void getInput(char code[]);
    void scramble(char code[]);
    
    
    int main()
    {
    	char code[6];
    	getInput(code);
    	//i want scramble and print functions to run here, although its not 
    	//possible because i have to repeat the fgets call in getInput
    	return 0;
    	
    }
    
    void getInput(char code[])
    {
    		printf("\nEnter your code : ");
        	while ( fgets( code, 6, stdin ) != NULL ) {
            if ( code[0] == 'Q' )
                break;
        
        	scramble(code);
    		
    		printf("\nEnter your code :");
        }
    }
    
    void scramble(char clode[])
    {
    	printf("done processing..");	
    }

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    So perhaps
    Code:
    while ( getInput(code,sizeof code) ) {
      scramble(code);
      printf("New code is %s\n", code );
    }
    Start making functions which return useful values.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Game design question
    By h3ro in forum Game Programming
    Replies: 6
    Last Post: 02-28-2008, 08:20 AM
  2. Question about engine design.
    By Shamino in forum Game Programming
    Replies: 9
    Last Post: 01-29-2008, 10:53 AM
  3. question about class design and overloading
    By l2u in forum C++ Programming
    Replies: 7
    Last Post: 12-13-2007, 02:02 PM
  4. database app design question
    By MPSoutine in forum Windows Programming
    Replies: 4
    Last Post: 12-02-2003, 10:13 PM
  5. design question: opinion
    By ggs in forum C Programming
    Replies: 2
    Last Post: 01-29-2003, 11:59 AM