Why does it print blank/garbage???

This is a discussion on Why does it print blank/garbage??? within the C Programming forums, part of the General Programming Boards category; how come this generates blank?? ive got a problem with this code,you see when i run it the questions dont ...

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

    Why does it print blank/garbage???

    how come this generates blank??
    ive got a problem with this code,you see when i run it the questions dont seem to come out thoughit was initialized already,,am usin a linkedlist is there somethin wrong with my paramtr passin?


    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
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > typedef char str20[21];
    > typedef char str70[71];

    Good lord that's ugly.

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

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Do not double post, it's annoying. Like you're saying "Hey, you're not moving fast enough for me, get hopping". When someone bothers to go through the long code that you posted then they'll answer your question, if you are in a hurry then break the program down to bare bones and chances are good you'll find the problem yourself.

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

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    28
    Originally posted by Prelude
    Do not double post, it's annoying. Like you're saying "Hey, you're not moving fast enough for me, get hopping". When someone bothers to go through the long code that you posted then they'll answer your question, if you are in a hurry then break the program down to bare bones and chances are good you'll find the problem yourself.

    -Prelude
    Thnks solved the problem already....believe me its the hanging of our server that made me double post ...i thought it didnt went through so i posted it consecutively....i meant no insult to anybody!!!

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    28
    at first glance, i'd say there has got to be quite a few things u could do to make this code less ugly...

    it's just ewwwww....

    man...put it some loop when u're building the arrays instead of hardcoding the #s..

    glad u got the problem fixed though.
    curiousity killed the cat, but it
    makes for one hell of a programmer.

    Alien.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by kreyes


    Thnks solved the problem already....believe me its the hanging of our server that made me double post ...i thought it didnt went through so i posted it consecutively....i meant no insult to anybody!!!
    Bull****. The SERVER made you post FOUR TIMES, all with DIFFERENT TITLES? Give me a break. We're not idiots. (Well, most of us aren't anyway...)

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

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    28
    Originally posted by quzah


    Bull****. The SERVER made you post FOUR TIMES, all with DIFFERENT TITLES? Give me a break. We're not idiots. (Well, most of us aren't anyway...)

    Quzah.
    fine if you dont want to believe!
    i thought it wasnt posted so i had to type it all over again..so what if its all with diff.titles am i suppose to remember the last one??! .... if you only knew how this darn server gets all f****d up for sooo long you'd understand why....
    anyway,im not gettin into any arguement or anythin just tryn to explain myself and that im not treatin ppl here as idiots..if ever i did why wld i even bother to ask help/suggestions?i respect ppl here coz i knpw they have great ideas and know better than i....i accept the fact that im no genius in this field ok? so can we just cut the crap out of this and go on with our lives pls??
    only the fittest survive!!!

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, 06:07 PM
  2. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 01: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, 09:13 PM
  5. Replies: 1
    Last Post: 07-31-2002, 12:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21