Thread: Why does it print blank ?

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    28

    Why does it print blank ?

    ive got a problem with this code,it doesnt seem to generate the question i initialized,it keeps on printin either garbage/blank spaces..any suggestions on this pls..?



    Code:
    #include<stdio.h>
    #include<string.h>    
    #include<stdlib.h>
    
    #define MAX 48
    #define ERROR "Invalid Input!"
    #define NOT_FOUND -1
    /*variable declarations*/
    
    typedef char str20[21];
    typedef char str70[71];
    
    typedef struct
    {
    	str70 strQuestions;
    	str20 strChoices[4];
    	char  cAns;
    	int  nLevel;
    }struct_Game;
    struct structNode
    {
    	struct_Game sGame;
    	struct structNode *pGPrev,*pGNext;
    };
    typedef struct structNode structGNodeType;
    typedef structGNodeType *ptrGNode;
    
    /*Function: void initialize_question()					*
     * Purpose: This function initializes values for aGame			*
     * Returns: nothing							*/
    void initialize_question(ptrGNode *pGame,struct_Game sGame)
    { int i,j,k;
    	ptrGNode pRun,pNew;
    	i=0,j=0;
     /*copies value of string to array*/
    	
     	if(*pGame==NULL)
    	{
    	strcpy((*pGame)->sGame.strQuestions," Ano ang pambansang hayop ng Pilipinas?");
    	strcpy((*pGame)->sGame.strChoices[0],"aso");
    	strcpy((*pGame)->sGame.strChoices[1],"pusa");
    	strcpy((*pGame)->sGame.strChoices[2],"kalabaw");
    	strcpy((*pGame)->sGame.strChoices[3],"kabayo");
    	(*pGame)->sGame.cAns = 'c';(*pGame)->sGame.nLevel = 1;
    	(*pGame)->pGPrev=NULL;
    	(*pGame)->pGNext=NULL;
    	pRun=*pGame;
    	}
    	pNew =(ptrGNode)malloc(sizeof(structGNodeType));
    	
    	strcpy(pNew->sGame.strQuestions," Sino ang pumatay kay Magellan?");
    	strcpy(pNew->sGame.strChoices[0],"Raja Soliman");
    	strcpy(pNew->sGame.strChoices[1],"Si Malakas");
    	strcpy(pNew->sGame.strChoices[2],"Raja Ulayman");
    	strcpy(pNew->sGame.strChoices[3],"Lapu-Lapu");
    	pNew->sGame.cAns = 'd'; pNew->sGame.nLevel = 1;
    	pRun->pGNext=pNew;
    	pNew->pGPrev=pRun;
    	pNew->pGNext=NULL;
    	pRun=pRun->pGNext;
    
    	pNew = (ptrGNode)malloc(sizeof(structGNodeType));
    	strcpy(pNew->sGame.strQuestions," Ano ang pambansang awit ng Pilipinas?");
    	strcpy(pNew->sGame.strChoices[0],"Lupang Hinirang");
    	strcpy(pNew->sGame.strChoices[1]," Bayang Magiliw");
    	strcpy(pNew->sGame.strChoices[2]," Perlas ng Silanganan");
    	strcpy(pNew->sGame.strChoices[3]," Lupa ng Araw");
    	pNew->sGame.cAns = 'a'; pNew->sGame.nLevel = 1;
    	pRun->pGNext=pNew;
    	pNew->pGPrev=pRun;
    	pNew->pGNext=NULL;
    	pRun=pRun->pGNext;
    
    	pNew = (ptrGNode)malloc(sizeof(structGNodeType));
    	strcpy(pNew->sGame.strQuestions," Ano ang tagalog ng rectangle?");
    	strcpy(pNew->sGame.strChoices[0],"kwadrado");
    	strcpy(pNew->sGame.strChoices[1],"tatsulok");
    	strcpy(pNew->sGame.strChoices[2],"parihaba");
    	strcpy(pNew->sGame.strChoices[3],"parisukat");
    	pNew->sGame.cAns = 'c'; pNew->sGame.nLevel = 1;
    	pRun->pGNext=pNew;
    	pNew->pGPrev=pRun;
    	pNew->pGNext=NULL;
    	pRun=pRun->pGNext;
    
    	pNew =(ptrGNode)malloc(sizeof(structGNodeType));
    	strcpy(pNew->sGame.strQuestions," Ano ang pangalan ng seawitch sa Disney movie na LittleMermaid?");
    	strcpy(pNew->sGame.strChoices[0],"Ariel");
    	strcpy(pNew->sGame.strChoices[1],"Flounder");
    	strcpy(pNew->sGame.strChoices[2],"Cruella");
    	strcpy(pNew->sGame.strChoices[3],"Ursula");
    	pNew->sGame.cAns = 'd'; pNew->sGame.nLevel = 1;
    	pRun->pGNext=pNew;
    	pNew->pGPrev=pRun;
    	pNew->pGNext=NULL;
    	pRun=pRun->pGNext;
    
    	pNew =(ptrGNode)malloc(sizeof(structGNodeType));
    	strcpy(pNew->sGame.strQuestions,"Saan nobela ni Rizal makikita si SIMOUN?");
    	strcpy(pNew->sGame.strChoices[0],"Noli Me Tangere");
    	strcpy(pNew->sGame.strChoices[1],"El Filibusterismo");
    	strcpy(pNew->sGame.strChoices[2],"Florante at Laura");
    	strcpy(pNew->sGame.strChoices[3],"Mi Ultimo Adios");
    	pNew->sGame.cAns = 'b'; pNew->sGame.nLevel = 2;
    	pRun->pGNext=pNew;
    	pNew->pGPrev=pRun;
    	pNew->pGNext=NULL;
    	pRun=pRun->pGNext;
    
    	pNew =(ptrGNode)malloc(sizeof(structGNodeType));	
    	strcpy(pNew->sGame.strQuestions," Saan kilala si Gabriel Flash Elorde?");
    	strcpy(pNew->sGame.strChoices[0],"bowling");
    	strcpy(pNew->sGame.strChoices[1],"boxing");
    	strcpy(pNew->sGame.strChoices[2],"chess");
    	strcpy(pNew->sGame.strChoices[3],"karate");
    	pNew->sGame.cAns = 'b'; pNew->sGame.nLevel = 2;
    pRun->pGNext=pNew;
    	pNew->pGPrev=pRun;
    	pNew->pGNext=NULL;
    	pRun=pRun->pGNext;
    
    	
    	
    	
    }	
    
    
    /* Function: Game_mod(ptrGNode*pGame,struct_Game sGame)					*
     * Purpose: This function enters the user to the game proper		*/
    			
    void Game_mod(ptrGNode *pGame,struct_Game sGame)
    {	ptrGNode pTemp;
    	int nNum,nCtr=3,nTemp,nAmt_won;
    	char cCont,cChoice ,cEnter;
    	pTemp=*pGame;
    	int arrlifeline[3]={1,2,3}; 
    	int arrPeso_level[16] =
    	{0,1000,2000,3000,5000,10000,20000,30000,40000,50000,100000,200000,300000,500000,1000000,2000000};
    	initialize_question(&*pGame,sGame);
    	/*nTemp=rand()%15;*/
    	cCont = display_instructions(cCont);
    		if(cCont=='Y' || cCont=='y')
    		{	scanf("%c",&cEnter);
    		  do
    	 	  {
    printf("You are going to the %dlevel\n",arrPeso_level[nTemp+1]);
    
       		  printf("You have %d lifelines left\n",nCtr);
    
    		  printf("\nYour question is :\n");
    		  
    		/*Calls subfunction*/
    		  cChoice =  get_answer(pTemp,sGame);//this ones the problem
    			/*evaluates user's answer*/
    		do
    		{
    		if(cChoice!='a'&&cChoice!='b'&&cChoice!='c'&&cChoice!='d'&&
    		cChoice!='1'&&cChoice!='2'&&cChoice!='3'&&cChoice!='x')
    		{	  
    			  printf("Invalid answer!\n");
    			  printf("Enter your answer again");
    			  
    			  scanf("%c",&cChoice);
    		}
            	}while(cChoice!='a' && cChoice!='b' &&
    				cChoice!='c' && cChoice!='d'&&
    		cChoice!='1' && cChoice!='2' && cChoice!='3' &&
    		cChoice!='x');
    			scanf("%c",&cEnter);				
    			if(cChoice == pTemp->sGame.cAns)
    			{
    			  printf("That's correct!\n");
    			  nTemp++;
    			  pTemp=pTemp->pGNext;
    			}
    			else if(cChoice == 'x' || cChoice == 'X')
    			{
    			  printf("You chose to end this game\n");
    			  printf("You receive %d pesos\n",arrPeso_level[nTemp]);
    			  printf("Congratulations!");
    			}
    			else if(cChoice=='a'||cChoice=='b'||cChoice=='c'|| cChoice=='d')
    			{
                               printf("Sorry,Wrong answer!\n");
    			  printf("You receive %d pesos\n",arrPeso_level[nTemp]);
    				Menu(&*pGame,sGame);       
    			}	
                          else if(cChoice=='1' || cChoice=='2' ||
    				cChoice=='3')
    			 nCtr = display_lifeline(nCtr,arrlifeline,cChoice,sGame);
    		/* Condition for bringing incorrect answer to safelevel*/
    				if(arrPeso_level[nTemp]/5==0)
    				  nAmt_won=0;
    				else if(arrPeso_level[nTemp]/5==1)
    				  nAmt_won=10000;
    				else if(arrPeso_level[nTemp]/5==2)
    				  nAmt_won==100000;
    				else if(arrPeso_level[nTemp]/5==3)
    				 { nAmt_won==2000000;
    				  printf("You're our lucky Millionaire,Congratulations!!");		
    				}
    		  	 
    	}while(cChoice==pTemp->sGame.cAns||cChoice=='1'||cChoice=='2'||
    	 cChoice==3||cCont=='Y'||cCont=='y'&& nTemp <16);
    	}
    
    
    	/*else part to exit program*/
    	else
    		printf("Program aborted by user!\n\n");
    		
    	}	
    /*Function:display_instructions()				*
      *Purpose : Prints Welcome message and reads value for choice	*
      *Called by: game_mod()					*
      *Receives: cCont(character)					*
      *Returns: cCont(Character)					*/
     
    char display_instructions(char cCont)
    { 	clear_screen();
    	printf("\n");
    	printf("+-----------------------------------------------+\n");
    	printf("|		WELCOME TO		        |\n");
    	printf("|	WHO WANTS TO BE A MILLIONAIRE!!!	|\n");
    	printf("| To START------------------------------ TYPE Y	|\n");
    	printf("| To TERMINATE/END---------------------- TYPE N |\n");
    	printf("+-----------------------------------------------+\n");
    	do
    	{
    	  printf("Enter your choice:");
    	  scanf("%c",&cCont);
    	 
    		if(cCont!='Y'&& cCont!='y'&& cCont!='N'&& cCont!='n')
                    printf("Wrong choice!\n");
    	}while(cCont!='Y'&& cCont!='y'&& cCont!='N'&& cCont!='n');
    
    	return cCont;		
    }/*end of function*/
    
    /*Function: int display_lifeline()				*
     *Purpose : This function displays and updates lifeline		*
     *Returns: integer						*
     *Note:	 1- call-a-friend,2-50/50,3-ask-the-audience		*/
    int display_lifeline(int nCtr, int arrlifeline[],char cChoice,struct_Game sGame)
    {	
    	int  nCount;
    	if(cChoice =='1')
    		nCount = 1;
    	else if(cChoice =='2')
    		nCount = 2;
    	else if(cChoice=='3')
    		nCount = 3;
    		if(nCount<=3 && nCount>=1)
    		{
    		
    		if(nCount==arrlifeline[0])
    		{
    		  printf("You chose call-a-friend\n");
    		  printf("\nDialing...\n");
    		  delay();
    		  printf("Chris: I think the answer is %c
    			\n",&sGame.cAns);//this one also generated none
    		printf("I'm 100% sure!");
    		  arrlifeline[0]=5; /*assigns a different value to array*/
    		  nCtr--;
    		}
    		else if(nCount==arrlifeline[1])
    		{
    		  printf("You chose 50/50\n");
    			display_50(sGame);
    		  arrlifeline[1]=6;
    		  nCtr--;
    		}
    		else if(nCount==arrlifeline[2])
    		{
    		  printf("You chose ask-the-audience\n");
    		  puts("a.40%");
    		 puts("b.15%");
    		 puts("c. 20%");
    		  puts("d. 25%");
    		  arrlifeline[2]=7;
    		  nCtr--;
    		}	
    	}	
    	return nCtr;
            }	/*end of function*/
    
    /* Function: char get_answer()							*
     * Purpose: This Function displays the question and throws answer to main()	*
     * Returns: character								*/
    
    char get_answer(ptrGNode pGame,struct_Game sGame)
    {	
    	int j;
    	char cChoice;
    	
    	if(strcmp(pGame->sGame.strQuestions,""))
    	{	/* nTemp = rand()%15;*/
    		puts(pGame->sGame.strQuestions);
    		for(j=0;j<4;j++)
    		{
    			if(j==0)
    			{
    			printf("a.");
    			puts(pGame->sGame.strChoices[j]);
    			
    			}
    			else if(j==1)
    			{	
    			printf("b.");
    			puts(pGame->sGame.strChoices[j]);
    			
    			}
    			else if(j==2)
    			{	
    			printf("c.");
    			puts(pGame->sGame.strChoices[j]);
    			
    			}	
    			else if(j==3)
    			{	
    			printf("d.");
    			puts(pGame->sGame.strChoices[j]);
    			
    			}
    		
    		}
    		
    		
    	}
    	printf("What is your answer?");
    	scanf("%c", &cChoice);
    	return cChoice;		
    }	/*end of function*/
    only the fittest survive!!!

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    This is your third post with the exact same question, I'm no longer going to look at questions you post. Show some courtesy, we're not morons.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    28
    hey,sorry ok there's sumthin wrong with my server(it keeps on hanging) so whenever i refresh it i thought it was gone already so i posted it all bak again....some of which are edited...ill delete my other post pertainin to my same question

    Im not treatin ppl here as morons FYI!!!

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    28

    Angry

    anyway,dont wana argue or anythin coz i already fixed the code myself..thanks anyway for your COMMENT!!
    Last edited by kreyes; 03-08-2002 at 12:07 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. merging linked lists
    By scwizzo in forum C++ Programming
    Replies: 15
    Last Post: 09-14-2008, 05:07 PM
  2. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  3. Scope And Parameter Passing
    By djwicks in forum C Programming
    Replies: 6
    Last Post: 03-28-2005, 08:26 PM
  4. What kind of programs should I start writing?
    By Macabre in forum C++ Programming
    Replies: 23
    Last Post: 04-12-2003, 08:13 PM
  5. Replies: 1
    Last Post: 07-31-2002, 11:35 AM