Thread: !Help! Similar to hangman game

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    2

    !Help! Similar to hangman game

    reposted below
    Last edited by xxdevillxx; 03-02-2011 at 07:17 PM.

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    Mate, nobody is going to bother reading through that, or very few people will unless you actually make some effort yourself and say WHAT particularly you have found is going wrong, what is your principal error? If it compiles Is there something crazy going on in the output? does the program loop forever?
    With that sort of info people can look at potential problem areas quickly, without reading lots of code.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    2
    hello again can someone please help...

    the program runs fine the first time but when i run it the second time it doesnt work as its suposed to-

    1- when user is asked to enter y-to continue and n- to stop playing it doesnt matter what user enters it just continues the game
    2-if i choose f to guess the film title the title is not covered by stars its name is just printed. sometimes the full movie sometimes half and tolower function doesnt work.
    3- and when i choose c the second time i run the program it just asks me to choose again f or c and if i pick it again program stops running or asks me to choose again f works fine appart from the problem above.


    if im still not giving enough info to get help please let me know ill write more...





    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <ctype.h>
    #include <stdlib.h>
    #include <time.h>
    #include <math.h>
    #include <string.h>
    
    FILE *fopen(), *fp;
    int lines,c,z,i,j;
    char star;
    char film[5000];
    char filmc[5000];
    char opt;
    char option2[100];
    char charg;
    char charf[100];
    int errors;
    
    
    void random(void); 
    void file(void);
    void options(void);
    void p_options(void);
    void character(void);
    void title(void);
    void wait(void);
    void yesno(void);
    
     void main()
    {
    	star='*';
    	i=0;
    	lines=1;
    	j=0;
    	errors = 1;
    
    	fp= fopen("films.txt","r");
    	random();
    	file();
    	printf("%d", z); //******
    	printf("%s",filmc);
    	options();
    	p_options();
    	fflush(stdin);
    }
    
    
    	
    void random()
    {   
    	srand(time(NULL));
    	z = 1 + rand() %45;
    }
    	
    void file()
    {
    	
    	while ( lines < z)
    	{
    		c = getc(fp);
    		if ( c == '\n')
    		{
    			lines++;
    		} 
    	}	
     
    	fgets(film,5000,fp);
    	strcpy(filmc,film);
    		
    	while ( filmc[i] != '\0' ) /* not at end of string */
    	{	//fflush(stdin);
    		film[i] = tolower(film[i]);
    		//fflush(stdin);
    		if (( filmc[i] >= 'A' &&  filmc[i] <='Z') || ( filmc[i] >='a' &&  filmc[i] <='z' ))
    		{
    			filmc[i] = star;
    		}
    		i++;
    	}
    }
    
    void options()
    {	
    	fflush(stdin);
    	printf("\nEnter c-C or f_F to guess!?!?!?:O");
    	printf("\nc-C == CHARACTER!");
    	printf("\nf-F == FULL TITLE!\n\t~ ");
    	opt = getchar();
    	fflush(stdin);
    	opt = tolower(opt);
    	fflush(stdin);
    }
    
    void p_options()
    {
    	if ( opt == 'c' )
    	{character();}
    	else if ( opt == 'f' )
    	{title();}
    	else
    	printf("Sorry but you have entered wrong character please\n try again!!idiot!!");
    }
    
    void character()
    {	
    	while(strcmp(film, filmc) != 0) 
    	{
    		printf("\n%s",film); //****************
    		printf("%s\n", filmc);
    		fflush(stdin);
    		printf("\nenter a letter to guess:\t");
    		fgets(charf,100,stdin);
    		charf[0] = tolower(charf[0]);
    			
    		if (isalpha(charf[0])) 
    		{
    			for(j = 0; j < strlen(film); j++)
    			{
    				if(film[j] == charf[0])
    				{
    				filmc[j] = charf[0];
    				}
    			}
    			printf("%s\n", filmc);
    		}
    		else 
    		printf("Only (a-z, A-Z)are allowed , try again:\n");
    		wait();
    		yesno();
    		options();
    		p_options();
    		fp= fopen("films.txt","r");
    		random();
    		file();
    		
    		
    	}	
    }
    
    void title()
    {	
    	printf("\n%s",film); //****************
    	printf("%s\n", filmc);
    	printf("\nEnter the title of the film:");
    	fgets(charf,100,stdin);
    	if (strcmp(film,charf) == 0)
    	{
    		printf("\n ******** Correct ********\n");
    		printf("\n***** WOW! You guessed it in one go!!! ****\n");
    	}
    		else if(strcmp(film,charf) != 0) 
    		{
    			printf("\n****Incorect, try again please ****\n");
    		}
    		wait();
    		yesno();
    		fp= fopen("films.txt","r");
    		random();
    		file();
    		options();
    		p_options();
    		
    		
    }
    
    void yesno()
    {
    	printf("\nWould you like to play(agiain) or to leave the game?");
    	printf("\ny-Y == play(again)");
    	printf("\nn-N == to leave(stop)");
    	fflush(stdin);
    	gets(option2);
    	fflush(stdin);
    	//option2[100] = tolower(option2[100]);
    	if ( option2[0] == 'y' || option2[0] == 'Y' )
    	{
    		fp= fopen("films.txt","r");
    		random();
    		file();
    		options();
    		p_options();
    	}
    	else if (option2[0] == 'n' || option2[0] == 'N' )
    	{return;}
    	else 
    	printf("sdasas");
    }
    
    void wait(void)
    {
    	char dummy[100];
    	printf("\n\n Press RETURN to continue:");
    	gets( dummy ) ;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Event driven game engine
    By abachler in forum Game Programming
    Replies: 9
    Last Post: 12-01-2009, 06:03 AM
  2. Replies: 15
    Last Post: 10-20-2009, 09:39 AM
  3. Open-source Game Project
    By Glorfindel in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 03-24-2009, 01:12 AM
  4. craps game & dice game..
    By cgurl05 in forum C Programming
    Replies: 3
    Last Post: 03-25-2006, 07:58 PM
  5. beach bar (sims type game)
    By DrKillPatient in forum Game Programming
    Replies: 1
    Last Post: 03-06-2006, 01:32 PM