C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old March 7th, 2002, 09:55 PM
kreyes kreyes is offline
dark angel
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Location: in your mind....
Posts: 2 kreyes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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*/

Reply With Quote
  #2  
Old March 14th, 2002, 03:31 PM
Analyser's Avatar
Analyser Analyser is offline
*bounce*
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2002
Location: Delft, The Netherlands
Posts: 509 Analyser User rank is Corporal (100 - 500 Reputation Level)Analyser User rank is Corporal (100 - 500 Reputation Level)Analyser User rank is Corporal (100 - 500 Reputation Level)Analyser User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 20 h 3 m 49 sec
Reputation Power: 9
Send a message via ICQ to Analyser
*sigh*

Nobody's going to wade through that much code, you know. You'll have to be more specific.

Try putting some diagnostic messages throughout your code (just some printf()'s will do), especially around code that you think -could- be part of the problem.

Once you've isolated the problem and find yourself unable to solve it, you could try posting it here.

Good luck
__________________
"A poor programmer is he who blames his tools."
http://analyser.oli.tudelft.nl/

Reply With Quote
  #3  
Old March 14th, 2002, 04:50 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
use your debugger! (nothing else to be added.....)
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > how come this generates blank??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway