Thread: what does this warningmean???

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

    Unhappy what does this warningmean???

    im using linux c and i cant seem to know whats wrong with this code that its been giving the warning:ansii c++ prohibits void* conversion.-----it keeps on giving this warnings whenever i use the malloc thing in linked list...pls help me..i have attached the code below :
    /* Name:
    Program name:
    Description: This program is a simplified version of Who Wants To Be a Millionaire!
    It includes Both the Maintenance and Game Module.
    */

    #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 prototypes*/
    void addQuestion(ptrGNode *pGame,struct_Game);
    void delQuestion(ptrGNode*,struct_Game);
    void Menu(ptrGNode*,struct_Game);
    void Maintenance_mod(ptrGNode*pGame,struct_Game sGame);
    void Game_mod(ptrGNode*,struct_Game);
    char display_instructions(char);
    int display_lifeline(int , int *,char,struct_Game );
    void display_Question(struct_Game);
    void initialize_question(ptrGNode*,struct_Game);
    char get_answer(ptrGNode,struct_Game);
    void view_Question(ptrGNode pGame,struct_Game);
    void view_All(ptrGNode);
    void view_Keyword(ptrGNode,struct_Game);
    void view_Level(ptrGNode,struct_Game);
    int find(ptrGNode);
    void display_50(struct_Game);
    void sort_Question(ptrGNode*,struct_Game);
    void bye();
    void save_Question(ptrGNode);
    void load_Question(ptrGNode*);
    void mod_Question(ptrGNode*,struct_Game);
    void display_50(struct_Game);
    void delay();
    void clear_screen();
    void deleteGNode(ptrGNode *pGame);

    main()
    { struct_Game sGame;
    ptrGNode pGame;
    initialize_question(&pGame,sGame);
    clear_screen();
    Menu(&pGame,sGame);


    }

    /* Function: Menu(arrGame aGame) *
    * Purpose: this function serves as the main menu in accessing the modules *
    * */
    void Menu(ptrGNode *pGame,struct_Game sGame)
    {
    int nChoice;
    char cEnter;
    clear_screen();
    puts("\n $ $ $ $ $ $ WHO WANTS TO BE A MILLIONAIRE! $ $ $ $ $\n");
    do
    {
    puts("\n ~ ~ ~ ~ ~ ~ MAIN MENU ~ ~ ~ ~ ~ ~\n");
    puts(" 1 - MAINTENANCE MODULE ");
    puts(" 2 - GAME MODULE ");
    puts(" 3 - EXIT \n");
    do
    {
    printf("Enter choice:");
    scanf("%d",&nChoice);
    if(nChoice<1 || nChoice >3)
    puts(ERROR);
    }while(nChoice<1 || nChoice>3);
    scanf("%c",&cEnter);
    switch(nChoice)
    {
    case 1: Maintenance_mod(&*pGame,sGame);
    break;
    case 2:Game_mod(&*pGame,sGame);
    break;
    case 3: puts("thank you for joining");
    bye();
    break;
    }
    } while(nChoice < 4);


    }

    /* Function: Maintenance_mod(ptrGNode pGame,struct_Game sGame) *
    * Purpose: This function serves as the menu for accessing maintenance options */

    void Maintenance_mod(ptrGNode *pGame,struct_Game sGame)
    {
    char cChoice,cEnter;

    clear_screen();
    puts("\n ~ ~ ~ ~ ~ ~ MAINTENANCE MODULE ~ ~ ~ ~ ~ ~ \n");
    puts(" A - ADD QUESTION ");
    puts(" D - DELETE QUESTION ");
    puts(" M - MODIFY QUESTION ");
    puts(" V - VIEW QUESTION ");
    puts(" T - SORT QUESTION ");
    puts(" S - SAVE QUESTION ");
    puts(" L - LOAD QUESTION ");
    puts(" X - EXIT QUESTION ");
    do{
    printf("Enter Choice:");
    scanf("%c",&cChoice);

    if(cChoice!='A'&&cChoice!='D'&&cChoice!='M'&&

    cChoice!='V'&& cChoice!='T'&& cChoice!='S'&& cChoice!='L'&& cChoice!='X')
    puts(ERROR);

    }while(cChoice!='A'&&cChoice!='D'&&cChoice!='M'&&c Choice!='V'&&cChoice!='T'&&cChoice!='S'&&cChoice!= 'L'&&cChoice!='X');




    switch(cChoice)
    {
    case'A': puts("\n ADD QUESTION\n");
    addQuestion(&*pGame,sGame);
    break;
    case'D': puts("\n DELETE QUESTION\n");

    delQuestion(&*pGame,sGame);
    break;
    case'M': puts("\n MODIFY QUESTION\n");
    mod_Question(&*pGame,sGame);
    break;
    case'V': puts("\n VIEW QUESTION\n");
    view_Question(*pGame,sGame);
    break;
    case'T': puts("\n SORT QUESTION\n");
    sort_Question(&*pGame,sGame);
    break;
    case'S': puts("\n SAVE QUESTION\n");
    save_Question(*pGame);
    break;
    case'L': puts("\n LOAD QUESTION\n");
    load_Question(&*pGame);
    break;
    case 'X'uts("\n EXIT \n");

    Menu(&*pGame,sGame);
    break;
    }



    }

    /* 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,500 00,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);
    /*evaluates user's answer*/
    do
    {
    if(cChoice!='a'&&cChoice!='b'&&cChoice!='c'&&cChoi ce!='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);
    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*/

    /*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 = 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 = 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 = 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 = 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 = 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 = 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;

    pNew = malloc(sizeof(structGNodeType));
    strcpy(pNew->sGame.strQuestions," Sino sa mga ss.ang hindi myembro ng 80s band naDuran2?");
    strcpy(pNew->sGame.strChoices[0],"Andy Taylor");
    strcpy(pNew->sGame.strChoices[1],"Tony Hadley");
    strcpy(pNew->sGame.strChoices[2],"Simon Le Bon");
    strcpy(pNew->sGame.strChoices[3],"Nick Rhodes");
    pNew->sGame.cAns = 'b'; pNew->sGame.nLevel = 2;
    pRun->pGNext=pNew;
    pNew->pGPrev=pRun;
    pNew->pGNext=NULL;
    pRun=pRun->pGNext;

    pNew = malloc(sizeof(structGNodeType));
    strcpy(pNew->sGame.strQuestions," Tungkol kanino ang pelikulang MommieDearest?");
    strcpy(pNew->sGame.strChoices[0],"Ingrid Bergman");
    strcpy(pNew->sGame.strChoices[1],"Grace Kelly");
    strcpy(pNew->sGame.strChoices[2]," Greta Garbo");
    strcpy(pNew->sGame.strChoices[3]," Joan Crawford");
    pNew->sGame.cAns = 'd'; pNew->sGame.nLevel = 2;
    pRun->pGNext=pNew;
    pNew->pGPrev=pRun;
    pNew->pGNext=NULL;
    pRun=pRun->pGNext;

    pNew = malloc(sizeof(structGNodeType));
    strcpy(pNew->sGame.strQuestions," Ano ang nickname kay IanThorpe,Australian Olympic Swimming?");
    strcpy(pNew->sGame.strChoices[0]," Thornado");
    strcpy(pNew->sGame.strChoices[1],"Mighty Thor");
    strcpy(pNew->sGame.strChoices[2]," Thorgue");
    strcpy(pNew->sGame.strChoices[3]," Thorpedo");
    pNew->sGame.cAns = 'd'; pNew->sGame.nLevel = 2;
    pRun->pGNext=pNew;
    pNew->pGPrev=pRun;
    pNew->pGNext=NULL;
    pRun=pRun->pGNext;

    pNew=malloc(sizeof(structGNodeType));
    strcpy(pNew->sGame.strQuestions," Kapag hinanap ka ng taga-BIR,may kaso ka na?");
    strcpy(pNew->sGame.strChoices[0],"tax Evasion");
    strcpy(pNew->sGame.strChoices[1],"jaywalking");
    strcpy(pNew->sGame.strChoices[2],"smokebelching");
    strcpy(pNew->sGame.strChoices[3],"illegal recruiting");
    pNew->sGame.cAns = 'a';pNew->sGame.nLevel = 3;
    pRun->pGNext=pNew;
    pNew->pGPrev=pRun;
    pNew->pGNext=NULL;
    pRun=pRun->pGNext;

    pNew = malloc(sizeof(structGNodeType));
    strcpy(pNew->sGame.strQuestions," Saan ang pinakamalaking isla ng Pilipinas?");
    strcpy(pNew->sGame.strChoices[0],"Panay");
    strcpy(pNew->sGame.strChoices[1],"Palawan");
    strcpy(pNew->sGame.strChoices[2],"Luzon");
    strcpy(pNew->sGame.strChoices[3],"Cebu");
    pNew->sGame.cAns = 'c'; pNew->sGame.nLevel = 3;
    pRun->pGNext=pNew;
    pNew->pGPrev=pRun;
    pNew->pGNext=NULL;
    pRun=pRun->pGNext;

    pNew=malloc(sizeof(structGNodeType));
    strcpy(pNew->sGame.strQuestions," Ano ang tawag sa headdress ng mga madre?");
    strcpy(pNew->sGame.strChoices[0],"wimple");
    strcpy(pNew->sGame.strChoices[1],"hob");
    strcpy(pNew->sGame.strChoices[2],"bittern");
    strcpy(pNew->sGame.strChoices[3],"camela");
    pNew->sGame.cAns = 'a';pNew->sGame.nLevel = 3;
    pRun->pGNext=pNew;
    pNew->pGPrev=pRun;
    pNew->pGNext=NULL;
    pRun=pRun->pGNext;

    pNew = malloc(sizeof(structGNodeType));
    strcpy(pNew->sGame.strQuestions," Sino ang doktor na nakadiskubre ng bakuna sa smallpox?");
    strcpy(pNew->sGame.strChoices[0],"Edward Jenner");
    strcpy(pNew->sGame.strChoices[1],"Alexander Fleming");
    strcpy(pNew->sGame.strChoices[2],"Irene Curie");
    strcpy(pNew->sGame.strChoices[3],"Ernest Cain");
    pNew->sGame.cAns = 'a';pNew->sGame.nLevel = 3;
    pRun->pGNext=pNew;
    pNew->pGPrev=pRun;
    pNew->pGNext=NULL;
    pRun=pRun->pGNext;

    pNew=malloc(sizeof(structGNodeType));
    strcpy(pNew->sGame.strQuestions," Pisika,ano ang ibig sabihin ng EMF?");
    strcpy(pNew->sGame.strChoices[0],"electromotive force");
    strcpy(pNew->sGame.strChoices[1],"electromagnetic field");
    strcpy(pNew->sGame.strChoices[2],"electromagnetic force");
    strcpy(pNew->sGame.strChoices[3],"electromotive field");
    pNew->sGame.cAns = 'a';pNew->sGame.nLevel = 3;
    pRun->pGNext=pNew;
    pNew->pGPrev=pRun;
    pNew->pGNext=NULL;
    pRun=pRun->pGNext;




    }



    /* Function:addQuestion(arrGame) *
    * Purpose: This function allows the user to add Questions in the game */

    void addQuestion(ptrGNode *pGame, struct_Game sGame)
    {
    int i,k,j,nLevel;
    ptrGNode pGTemp,pNew=NULL;
    char cChoice,cEnter,cChoice2,cAns;
    str70 strTemp1;
    str20 strTemp2[4];
    i=0;
    printf("\n ~ ~ ~ ~ ~ ADD QUESTION ~ ~ ~ ~ ~ \n");
    do
    {

    printf("Enter Question:");
    gets(strTemp1);
    scanf("%c",&cEnter);
    if(strlen(strTemp1) > 70)

    puts("Question should be 70 characters or less!");
    else if(!strcmp(strTemp1,""))
    puts("Question canot be Null!!");

    else
    { pGTemp=*pGame;

    while (pGTemp!=NULL && strcmp(strTemp1,pGTemp->sGame.strQuestions) &&
    strcmp(pGTemp->sGame.strQuestions,""))
    {
    /*searches if question already exists*/


    if (strcmp(strTemp1,pGTemp->sGame.strQuestions)==0)
    puts("Question already exists");


    else if(pGTemp==NULL)
    {
    pNew = malloc(sizeof(structGNodeType));
    pNew->pGPrev=NULL;
    pNew->pGNext=NULL;
    pGTemp=pNew;
    strcpy(pNew->sGame.strQuestions,strTemp1);
    }
    if(!(*pGame)) /*if list is empty*/
    *pGame=pNew; /*insert in front */
    else /*if list not empty*/
    {
    pGTemp=*pGame;
    while(pGTemp->pGNext!=NULL)
    /*while pGTemp is not pointing to the last node*/
    pGTemp=pGTemp->pGNext;
    pGTemp->pGNext=pNew;
    pGTemp->pGPrev=pGTemp;
    /*insert at the end*/
    }
    }

    printf("Enter Choices(a-d):\n");
    gets(strTemp2[0]);

    for(k=0;k<4;k++)
    {
    if(k==0)
    { printf("a.");
    gets(strTemp2[k]);

    }
    if(k==1)
    {
    do{ printf("b.");
    gets(strTemp2[k]);

    if(strcmp(strTemp2[0],strTemp2[1])==0)
    puts("Choices cannot be the same!");


    }while(strcmp(strTemp2[0],strTemp2[1])==0);
    }
    if(k==2)
    {
    do{
    printf("c.");
    gets(strTemp2[k]);

    if(!strcmp(strTemp2[0],strTemp2[2]) ||
    !strcmp(strTemp2[1],strTemp2[2]))
    puts("Choices cannot be the same!");

    } while(!strcmp(strTemp2[0],strTemp2[2])||
    !strcmp(strTemp2[1],strTemp2[2]));
    }
    if(k==3)
    {
    do{
    printf("d.");
    gets(strTemp2[k]);

    if(!strcmp(strTemp2[0],strTemp2[3])||!strcmp(strTemp2[1],strTemp2[3])||!strcmp(strTemp2[2],strTemp2[3]))
    puts("Choices cannot be the same!");



    }while(!strcmp(strTemp2[0],strTemp2[3])||!strcmp(strTemp2[1],strTemp2[3])||!strcmp(strTemp2[2],strTemp2[3]));

    }
    if (strlen(strTemp2[k])>20)
    puts("Choices should only have 20 characters or less");
    else if(!strcmp(strTemp2[k],""))
    puts("Choices cannot be NULL!");
    else
    strcpy(pNew->sGame.strChoices[k],strTemp2[k]);
    }
    do
    {
    printf("Enter Answer (a-d)");
    scanf("%c", &cAns);
    scanf("%c",&cEnter);
    if(cAns!='a'&& cAns!='b' && cAns!='c' && cAns!='d')
    puts(ERROR);
    else
    pNew->sGame.cAns=cAns;
    }while(cAns!='a' && cAns!='b' && cAns!='c' && cAns!='d');
    do{
    printf("Enter level(1-3)");
    scanf("%d", &nLevel);
    scanf("%c",&cEnter);
    if(nLevel!=1&& nLevel!=2&&nLevel!=3)
    puts(ERROR);
    else
    pNew->sGame.nLevel=nLevel;
    }while(nLevel!=1&& nLevel!=2&&nLevel!=3);

    pNew=NULL;


    pGTemp=pGTemp->pGNext;

    puts("any more additional Questions?(y/n)");
    scanf("%c",&cChoice);
    scanf("%c",&cEnter);
    if(cChoice!='y'&&cChoice!='Y'&&cChoice!='n'&&cChoi ce!='N')
    puts(ERROR);
    else
    {
    printf("Do you want to view the added questions?(y/n)");
    scanf("%c",&cChoice2);
    scanf("%c",&cEnter);
    if(cChoice2=='y'||cChoice2=='Y')


    view_Question(*pGame,sGame);
    else
    Maintenance_mod(&*pGame,sGame);
    }
    }
    } while(cChoice=='y'||cChoice=='Y'&& pGTemp!=NULL);




    }

    /*Function:delQuestion *
    *Purpose: This function allows the user to delete questions */
    void delQuestion(ptrGNode *pGame, struct_Game sGame)
    { ptrGNode pTemp,pDel;
    int i,j,k, nDel,nNum,nCtr=1;
    char cChoice,cEnter,cChoice2;

    pTemp=*pGame;
    puts("\n ~ ~ ~ ~ ~ DELETE QUESTION ~ ~ ~ ~ ~ \n");
    do{

    printf("Question no.to delete? ");
    scanf("%d",&nDel);
    scanf("%c",&cEnter);
    if(pTemp==NULL)
    puts("Question is empty?!\n");
    else
    while(pTemp!=NULL&&nCtr!=nDel)
    nCtr++;
    pTemp=pTemp->pGNext;
    if(nCtr==1&&nDel==1)
    { pDel=pTemp;
    pTemp=pTemp->pGNext;
    if(pTemp!=NULL)
    pTemp->pGPrev=NULL;
    printf("\n Question %d deleted...\n\n",&nDel);
    free(pDel);
    pDel==NULL;
    }


    else if(nCtr==nDel)
    {
    pDel=pTemp;
    pTemp=pTemp->pGPrev;
    pTemp->pGNext->pGPrev=pTemp;
    printf("\nQuestion %d deleted...\n\n",&nDel);
    free(pDel);
    pDel=NULL;
    }


    else if(pTemp==NULL)
    puts("Index does not exist");

    printf("Any more questions to delete?(y/n)");
    scanf("%c",&cChoice);
    scanf("%c",&cEnter);
    if(cChoice!='n'&&cChoice!='N'&&cChoice!='y'&&cChoi ce!='Y')
    puts(ERROR);
    else
    printf("Do you want to view updated questions?(y/n)");
    scanf("%c",&cChoice2);
    scanf("%c",&cEnter);
    if(cChoice2=='y'||cChoice2=='Y')

    view_Question(*pGame,sGame);
    else
    Maintenance_mod(&*pGame,sGame);
    }while(cChoice=='y'||cChoice=='Y'&& i < MAX);

    }



    /* Function:view_Question *
    * Purpose: This function allows user to view currently entered questions *
    * Note: accesses 3 other specific functions to view */

    void view_Question(ptrGNode pGame,struct_Game sGame)
    {
    int nChoice,i=0;
    char cEnter;

    clear_screen();
    puts("\n ~ ~ ~ ~ ~ ~ VIEW QUESTIONS ~ ~ ~ ~ ~ ~\n");
    puts(" 1 - VIEW ALL ");
    puts(" 2 - VIEW BY KEYWORD ");
    puts(" 3 - VIEW BY LEVEL ");
    puts(" 4 - EXIT ");
    do{
    printf("Enter Choice:");
    scanf("%d", &nChoice);
    if(nChoice<1 || nChoice>4)
    {
    puts(ERROR);
    puts("1-4 only");
    }
    }while(nChoice<1 || nChoice>4);

    switch(nChoice)
    {
    case 0:
    case 1: view_All( pGame);
    break;
    case 2: view_Keyword(pGame,sGame);
    break;
    case 3: view_Level( pGame,sGame);
    break;
    case 4: scanf("%c",&cEnter);
    Maintenance_mod(&pGame,sGame);

    }

    }

    /* Function:view_All *
    * Purpose: This function allows user to view all questions */

    void view_All(ptrGNode pGame)
    { int i=0,j, k = 3,l;
    char cEnter;
    ptrGNode pTemp;
    if(!pGame)
    puts("\n There are no Questions!");
    else{
    pTemp=pGame;
    while(pTemp!=NULL&&strcmp(pTemp->sGame.strQuestions,""))
    {
    for(j=i;j<k; j++)
    {
    puts(pTemp->sGame.strQuestions);
    for(l=0;l<4;l++)
    puts(pTemp->sGame.strChoices[l]);
    printf("The answer is %c\n",pTemp->sGame.cAns);
    printf("The level is %d\n",pTemp->sGame.nLevel);
    pTemp=pTemp->pGNext;
    }
    }
    printf("Press enter to continue...");
    scanf("%c",&cEnter);
    i+=3;
    k+=3;

    }
    }

    /* Function: view_Level *
    * Purpose: This function views the questions by difficulty level */

    void view_Level(ptrGNode pGame,struct_Game sGame)
    { ptrGNode pTemp;
    int nNumLevel;
    char cEnter;
    int i = 0;
    clear_screen();
    do{
    i = 0;
    puts("\n ~ ~ ~ ~ ~ VIEW BY DIFFICULTY LEVEL ~ ~ ~ ~ ~ \n");
    puts(" 1 - EASY ");
    puts(" 2 - MODERATE ");
    puts(" 3 - HARD ");
    puts(" 4 - BACK ");
    do{
    printf("Enter Choice[1-4]");
    scanf("%d",&nNumLevel);
    if(nNumLevel<1||nNumLevel>4)
    {
    puts(ERROR);
    puts("1-4 only");
    }
    }while(nNumLevel<1||nNumLevel>4);
    pTemp=pGame;
    switch(nNumLevel)
    {
    case 1: while (pTemp!=NULL)
    {if(pTemp->sGame.nLevel==1)
    display_Question(pTemp->sGame);

    pTemp=pTemp->pGNext;

    }
    break;

    case 2:
    while (pTemp!=NULL)
    {if(pTemp->sGame.nLevel==2)
    display_Question(pTemp->sGame);

    pTemp=pTemp->pGNext;

    }
    break;

    case 3: while (pTemp!=NULL)
    {if(pTemp->sGame.nLevel==3)
    display_Question(pTemp->sGame);
    pTemp=pTemp->pGNext;

    }
    break;

    case 4:
    view_Question(pGame,sGame);
    break;
    }
    }while(nNumLevel<1||nNumLevel>4);
    }

    /* Function:mod_Question *
    * Purpose: This function allows user to edit Question attributes */

    void mod_Question(ptrGNode *pGame,struct_Game sGame)
    { ptrGNode pTemp,pMod;
    int nMod,k,nNewLevel,nCtr;
    char cNewAns, cChoice,cEnter,cChoice2;
    str70 strTemp1;
    str20 strTemp2[4];
    pTemp=*pGame;
    do{
    printf("Enter question no.to be modified: ");
    scanf("%d",&nMod);
    scanf("%c",&cEnter);
    if(nMod==0)
    puts(ERROR);
    else{
    if(!strcmp(pTemp->sGame.strQuestions,""))
    puts("Question no.does not exist!\n");
    else
    {pTemp=*pGame;
    while(pTemp!=NULL&&nMod!=nCtr)
    nCtr++;
    pTemp=pTemp->pGNext;
    if(pTemp==NULL)
    puts("Question no.does not exist!\n");
    else if(nMod==nCtr)
    puts(pTemp->sGame.strQuestions);
    for(k=0; k<4; k++)
    puts(pTemp->sGame.strChoices[k]);

    printf("Answer is %c\n", pTemp->sGame.cAns);
    printf("Level is %d\n",pTemp->sGame.nLevel);
    }
    }
    printf("Enter new Question:");
    gets(strTemp1);

    if(strlen(strTemp1)>70)

    printf("question should be 70 characters or less!");
    else
    {
    pMod = malloc(sizeof(structGNodeType));
    pMod->pGNext=pTemp;
    pMod=pTemp;
    pTemp=pTemp->pGNext;
    strcpy(pMod->sGame.strQuestions,strTemp1);

    }
    printf("Enter new choices(a-d):\n");
    for(k=0;k<4;k++)
    {
    if(k==0)
    {
    printf("a.");
    gets(strTemp2[k]);

    }
    if(k==1)
    {
    do{
    printf("b.");
    gets(strTemp2[k]);
    if(!strcmp(strTemp2[0],strTemp2[1]))
    puts("Choices cannot be the same!");
    }while(!strcmp(strTemp2[0],strTemp2[1]));
    }
    if(k==2)
    {
    do{
    printf("c.");
    gets(strTemp2[k]);


    if(!strcmp(strTemp2[0],strTemp2[2])||!strcmp(strTemp2[1],strTemp2[2]))
    puts("Choices cannot be the same!");



    }while(!strcmp(strTemp2[0],strTemp2[2])||!strcmp(strTemp2[1],strTemp2[2]));

    }
    if(k==3)
    { do{
    printf("d.");
    gets(strTemp2[k]);


    if(!strcmp(strTemp2[0],strTemp2[3])||!strcmp(strTemp2[1],strTemp2[3])||!strcmp(strTemp2[2],strTemp2[3]))
    puts(" Choices cannot be the same!");


    }while(!strcmp(strTemp2[0],strTemp2[3])||!strcmp(strTemp2[1],strTemp2[3])||!strcmp(strTemp2[2],strTemp2[3]));
    }
    if (strlen(strTemp2[k])>20)
    puts("choices must be 20 characters or less");
    else

    strcpy(pMod->sGame.strChoices[k],strTemp2[k]);

    }

    do{
    printf("Enter new Answer: ");
    scanf("%c",&cNewAns);
    scanf("%c",&cEnter);
    if(cNewAns!='a'&&cNewAns!='b'&&cNewAns!='c'&&cNewA ns!='d')
    printf("\nAnswer must be a-d only!\n");
    else
    pMod->sGame.cAns=cNewAns;

    }while(cNewAns!='a'&& cNewAns!='b'&&cNewAns!='c'&&cNewAns!='d');
    do{ printf("Enter new level(1-3):");
    scanf("%d",&nNewLevel);
    scanf("%c",&cEnter);
    if(nNewLevel <1 ||nNewLevel>3)
    puts(ERROR);
    else
    {
    pMod->sGame.nLevel = nNewLevel;
    if( pMod->sGame.nLevel == 1)
    printf("The Level is Easy!\n");
    else if( pMod->sGame.nLevel == 2)
    printf("The Level is Moderate\n");
    else if ( pMod->sGame.nLevel == 3)
    printf("The Level is Hard\n");
    }
    }while(nNewLevel<1 ||nNewLevel>3);
    printf("Any more modifications(Y/N)");
    scanf("%c",&cChoice);
    scanf("%c",&cEnter);
    if (cChoice!='Y'&&cChoice!='y' &&cChoice!='N'&&
    cChoice!='n')
    puts(ERROR);
    else

    printf("Do you want to view modifications?(y/n)");
    scanf("%c",&cChoice2);
    scanf("%c",&cEnter);
    if(cChoice2=='y'||cChoice2=='Y')
    view_Question(pMod,sGame);
    else
    Maintenance_mod(&*pGame,sGame);
    }while(cChoice=='y'||cChoice=='Y');
    }

    /* Function: display_Question(arrGame,int) *
    * Purpose: This function displays the question by a specific info. *
    * Note: The integer value specifies which question to display */

    void display_Question(struct_Game sGame)
    { int k;


    puts(sGame.strQuestions);
    for(k=0;k<4; k++)
    {
    if(k==0)
    { printf("a.");
    puts(sGame.strChoices[k]);

    }
    if(k==1)
    { printf("b.");
    puts(sGame.strChoices[k]);

    }
    if(k==2)
    { printf("c.");
    puts(sGame.strChoices[k]);

    }
    if(k==3)
    { printf("d.");
    puts(sGame.strChoices[k]);

    }
    }
    printf("The answer is %c\n", sGame.cAns);

    if(sGame.nLevel == 1)
    printf("The Level is Easy!\n");
    else if(sGame.nLevel == 2)
    printf("The Level is Moderate\n");
    else if (sGame.nLevel == 3)
    printf("The Level is Hard\n");

    }

    /* Function: save_Question(arrGame aGame) *
    * This function saves the question to a file ext. *.wwm */

    void save_Question(ptrGNode pGame)
    { ptrGNode pTemp;
    str20 strFile;
    FILE *pFile;
    printf("Enter filename: \n");
    gets(strFile);
    if(pFile=fopen(strFile,"wb"))
    { pTemp=pGame;
    while(pTemp!=NULL)
    { fwrite(&(pTemp->sGame),sizeof(struct_Game),1,pFile);
    pTemp=pTemp->pGNext;
    }
    fclose(pFile);
    puts("\nGame saved...\n");
    pTemp=NULL;
    }
    else
    puts("\n Error opening file!!!\n");
    }

    /* Function: load_Question *
    * Purpose: This function loads the content of wwm file */

    void load_Question(ptrGNode *pGame)
    { ptrGNode pLast=NULL,pNew;
    FILE *pFile;
    str20 strFile;
    printf("\n Enter filename: ");
    gets(strFile);
    if(pFile=fopen(strFile,"rb"))
    { deleteGNode(&*pGame);
    pNew=malloc(sizeof(structGNodeType));
    while(fread(&(pNew->sGame),sizeof(struct_Game),1,pFile))
    {
    pNew->pGNext=NULL;
    pNew->pGPrev=NULL;
    if(!(*pGame))
    *pGame=pNew;
    else
    { pLast->pGNext = pNew;
    pNew->pGPrev = pLast;
    }
    pLast=pNew;
    pNew=malloc(sizeof(structGNodeType));
    }
    puts("\nLoading successfull...\n");
    fclose(pFile);
    free(pNew);
    pNew=NULL;
    }
    else
    puts("Error reading file!!!\n");
    pLast=NULL;
    }

    void deleteGNode(ptrGNode *pGame)
    {
    ptrGNode pDel=NULL;
    while(*pGame!=NULL)
    {
    pDel=*pGame;
    *pGame=(*pGame)->pGNext;
    free(pDel);
    pDel=NULL;
    }
    }

    void delay()
    {
    int i,j=0;
    for(i=0;i<55555555;i++)
    j++;
    }

    void display_50(struct_Game sGame)
    { int i;
    puts(sGame.strQuestions);
    for(i=0;i<4;i++)
    { if(sGame.cAns=='a'||sGame.cAns=='c')
    { if(i==1)
    { printf("b.");
    puts(sGame.strChoices[i]);
    }
    if(i==3)
    { printf("d.");
    puts(sGame.strChoices[i]);
    }
    }
    else if(sGame.cAns=='b'||sGame.cAns=='d')
    { if(i==0)
    {
    printf("a.");
    puts(sGame.strChoices[i]);
    }
    if(i==2)
    {
    printf("c.");
    puts(sGame.strChoices[i]);
    }
    }
    }
    }
    /* Function : bye() *
    * Purpose: Prints out a bye message to user for exit */

    void bye()
    {
    printf("\n --- | --- _ _ ");
    printf("\n | | | | | | --- ");
    printf("\n | __ --- --- -- |___| |____| |___ ");
    printf("\n | || || || | | | || | ");
    printf("\n | || || || | | | || | ");
    printf("\n ---- --- --- -- ---- -- --- ");
    }
    /* Function: sort_Question(arrGame aGame) *
    * Purpose: This function sorts the question based on difficulty level */

    void sort_Question(ptrGNode *pGame,struct_Game sGame)
    {ptrGNode pTemp;
    int nCtr,i;
    char cEnter;
    nCtr = 0;
    pTemp=*pGame;
    while(pTemp!=NULL)
    {
    if(pTemp->sGame.nLevel == 1)
    { display_Question(pTemp->sGame);
    printf("Press enter to continue...\n");
    scanf("%c",&cEnter);

    }
    else if(pTemp->sGame.nLevel ==2)
    {display_Question(pTemp->sGame);
    printf("Press enter to continue...\n");
    scanf("%c",&cEnter);

    }
    else if(pTemp->sGame.nLevel ==3)
    { display_Question(pTemp->sGame);
    printf("Press enter to continue...\n");
    scanf("%c",&cEnter);

    }

    }

    }
    int find(ptrGNode pGame)
    { ptrGNode pTemp;
    int nCtr,i,j,k,l,m,nVal;
    str70 strTemp;

    char sKey[31];
    int nFound=0,nWhere;
    nCtr =0;
    do{printf("\n\n Enter Keyword:>");
    scanf("%s",sKey);

    if(strlen(sKey)>31)

    printf("Keyword must only be 30 characters or less");

    }while(strlen(sKey)>31);
    if(sKey[0]=='\0')
    return(NOT_FOUND);
    else
    {pTemp=pGame;
    j=0;

    while(pTemp!=NULL)
    {
    for(i=0;i<strlen(pTemp->sGame.strQuestions);i++)
    {
    while(pTemp->sGame.strQuestions[i]!='\0')
    {
    strTemp[j]=pTemp->sGame.strQuestions[i];
    j++;
    }
    strTemp[j]='\0';

    if(!strcmp(strTemp,sKey))
    {
    nFound=1;
    return(nCtr);
    }
    else
    nCtr++;
    pTemp=pTemp->pGNext;
    }
    }
    }
    if(nFound==1)
    nWhere=nCtr;
    else
    nWhere=NOT_FOUND;

    return(nWhere);
    }





    /*Function: view_Keyword *
    * Purpose: this function displays the question matching the keyword *
    * Note: Calls the function int find() */

    void view_Keyword(ptrGNode pGame,struct_Game sGame)
    {ptrGNode pTemp;
    int nNum,nChoice;

    pTemp=pGame;
    do
    {printf("\n ~ ~ ~ ~ ~ VIEW KEYWORD ~ ~ ~ ~ ~ \n");
    nNum = find(pGame);
    if( nNum==-1)

    printf("not found!");
    else

    display_Question(pTemp->sGame);
    printf(" Would you like to look up another(1-yes/0-no)?");
    scanf("%d",&nChoice);

    if(nChoice==1)
    view_Keyword(pGame,sGame);
    else if(nChoice==0)
    view_Question(pGame,sGame);
    else
    puts(ERROR);
    }while(nChoice==1);



    }


    /************************************************** **************************

    Clear Screen Function

    ************************************************** **************************/

    void clear_screen()
    { int nctr=0;
    do
    {printf("\n");
    nctr++;
    }while(nctr!=51);
    }

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Calls to malloc return a generalized pointer to an area of memory, a void pointer. You need to cast the return value from these function calls to the appropriate type. In this case it would appear you need to do something like this for all your malloc calls:

    Code:
    pNew = (ptrGNode) malloc( sizeof( structGNodeType ) );
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    28
    hi! i did the (ptrGNode) thing in hte malloc and all is fine now no errors but still it has segmentation fault!!how come what might be the possible cause of this here???
    only the fittest survive!!!

  4. #4
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    1000+ Lines of code is too long to submit
    that way, better to submit as a file.

    You should first compile your project with gcc -Wall -g and fix all the warnings and remove gets.

    Tnen by running the debugger
    gdb ./a.out and then typing in run you can get

    Code:
    Program received signal SIGSEGV, Segmentation fault.
    0x8049596 in initialize_question (pGame=0xbffffa68, sGame={
          strQuestions = "\000<\001@\000<\001@\003\000\000\000p>\001@\001\000\000\000Ðúÿ¿´\236\000@'\001\001@ >\001@\a\000\000\000w\203\004\b\220õ\001@\000<\001@` \006@\016\236\000@°ç\004\bP6\001@Sæ\r", strChoices = {
            "@´\236\000@ð;\001@à>\001@Ð\201\004\b¼ç\004\b", 
            "\220\203\004\bZá\r@°ç\004\bP6\001@Sæ\r@\001", 
            "\000\000\000Lá\r@ð6\001@\bûÿ¿\231\206\004\b°ç", 
            "\004\b è\004\b\030ûÿ¿hn\003@¸Þ\016@0 "}, cAns = 64 '@', 
          nLevel = -1073743064}) at tmp.c:400
    400         pRun->pGNext = pNew;
    So you know that pRun is a invalid pointer and you can tell that pRun is only going to equal *pGame only if *pGame = NULL. Which means your either going to referance a null pointer or your going to referance a uninitialized pointer. To see the value of pRun do
    print pRun and to see what pGame referances do
    x pGame.
    Last edited by Nick; 03-03-2002 at 11:29 PM.

  5. #5
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    Anyways I think there's probably many more bugs than that one in your program.

  6. #6
    Registered User
    Join Date
    Feb 2002
    Posts
    28
    thanks for the reply..when i opened the attachment it kinda opened up as some sort of blurred text..anyway,im not that good in manipulating still stuffs like this so if you still have any suggestions itll be more than welcomed please!thanx
    only the fittest survive!!!

Popular pages Recent additions subscribe to a feed