View Single Post
Old 04-24-2005, 01:40 PM   #6 (permalink)
rogue
Registered User
 
Join Date: Apr 2005
Posts: 9
rogue is on a distinguished road
valmont quick question

What i'm trying to do is make a wordgame to accept a wpord upto 20 letters. and then the program will spell it backwards.

This is the code i am working with.i need to get case3 to go to my word game 1. now instead of a print f(display) i need to make a function to open wordgame1. i am a little lost on how to do this. i think i am on the right track but not sure. I just want to know am i close to getting the function to work ?
Yes or no.
i think the statement i need is soemthing like this :

DisplayWordGame1();
fflush(stdin);





/*program to wordgame1*/

/* AUTHOR: Valerie */

/* DATE: 4/20/05 */





Code:
/* DisplayMenu.  */ 

#include <stdio.h> 
#include <stdlib.h> 
#include <conio.h> 
#include <string.h> 

void DisplayMenu(void); 
void WordGame1(void); 

int main() 
{ 
        char    UserResponse; 





        DisplayMenu(); 
        fflush(stdin); 
        UserResponse = getch(); 

        while (UserResponse != '1'&& UserResponse !='2'&&  UserResponse != '3' 
                &&UserResponse != '4'&& UserResponse !='5') 
        { 
                fflush(stdin); 
                printf("%c", 7); 
                UserResponse = getch(); 


        } 
        while (UserResponse != '5') 
        { 
                switch(UserResponse) 
        { 

                case '1':       printf("\n\tYou have selected 1"); 
                                break; 

                case '2':       printf("\n\tYou have selected 2"); 
                                break; 

                case '3':		
						 
                                break; 


                case '4':       printf("\n\tYou have selected 4"); 
                        break; 


        } 


        printf("\n\n\n\tHit any key to continue...."); 
                fflush(stdin); 
                getch(); 
        } 


        DisplayMenu(); 
        fflush(stdin); 
        UserResponse = getch(); 

        while (UserResponse != '1'&& UserResponse !='2'&&  UserResponse != '3' 
                &&UserResponse != '4'&& UserResponse !='5') 
        { 
                fflush(stdin); 
                printf("%c", 7); 
                UserResponse = getch(); 
        } 
        printf("\n\nGoodbye\n\n\n"); 
        return 0; 
        } 

void DisplayMenu(void) 
        { 
        system("cls"); 
        printf("\n\t1.Sequential update"); 
        printf("\n\t2.Control break"); 
        printf("\n\t3.Word game 1"); 
        printf("\n\t4.Word Game2"); 
        printf("\n\t5.Quit"); 

		} 
        void WordGame1(void) 

        #include <stdio.h> 
        #include <string.h> 
        #define LINE_SIZE 20 

{ 
char Frontwards[LINE_SIZE +1], Backwards[LINE_SIZE+1]; 
int i, j; 

printf("Please enter word up to 20 letters: "); 
fflush(stdout); 
if(!fgets(Frontwards, LINE_SIZE, stdin)) 
   { 
     printf("Error reading word from stdin\n"); 

   } 
/* correct for the '\n' and '\0' from the read string */ 
        j = strlen (Frontwards) -2; 
for(i = 0; j >= 0; ) 
   Backwards[++i] = Frontwards[--j]; 
/* make sure reversed word isn't ending in garbage */ 
Backwards[i] = '\0'; 
printf("Read word was: %s", Frontwards); 
printf("Backwards: %s\n", Backwards); 


	{
	printf("\n\n\n\tHit any key to continue...."); 
                fflush(stdin); 
                getch(); 
	}
}

Last edited by Valmont; 04-24-2005 at 03:03 PM.
rogue is offline   Reply With Quote