LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-02-2009, 01:43 AM   #1
jbabs
LQ Newbie
 
Registered: Dec 2009
Posts: 1

Rep: Reputation: 0
Programming Jeopardy in C... HELP!


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define JEOPARDY 30
#define TRUE 1
#define FALSE 0


typedef char string30[JEOPARDY+1] ;
typedef char string15[16] ;
typedef char string5[6] ;

struct GamesTag
{
string30 strCategory[5], strQuestion[5][5], strAnswer[5][5], strValue[5][5], strFQues, strFAns; ;
string15 strGameName;
struct GamesTag *pLink;
};

typedef struct GamesTag *ptrGame;

void deleteCategory(ptrGame *pGames, string30 strCategoryToDelete)
{
int i = 0, j = 0;
ptrGame pPrevious, pCurrent ;

/* This function deletes the category that the user inputs. */

if(*pGames == NULL)
printf("List is Empty.\n") ;

else if(strcasecmp(strCategoryToDelete, (*pGames)->strCategory[j][i]) == 0)
{
pCurrent = *pGames ;
*pGames = (*pGames)->pLink ;
free(pCurrent) ;
}
else
{
pCurrent = *pGames ;

while(pCurrent != NULL && strcasecmp(strCategoryToDelete, pCurrent->strCategory) != 0)
{
pPrevious = pCurrent ;
pCurrent = pCurrent->pLink ;
}

if(pCurrent != NULL)
{
pPrevious->pLink = pCurrent->pLink ;
free(pCurrent);
}
else
printf("Category does not exist.\n\n") ;
}
while(i < 5)
{
for( j = 0 ; j < 31 ; j++)
{
pCurrent->strQuestion[i][j] = '\0';
pCurrent->strAnswer[i][j] = '\0';
pCurrent->strValue[i][j] = '\0';

}


strcpy(pCurrent->strQuestion[i], pCurrent->strQuestion[i+1]) ;
strcpy(pCurrent->strAnswer[i], pCurrent->strAnswer[i+1]) ;
strcpy(pCurrent->strValue[i], pCurrent->strValue[i+1]) ;

i++ ;
}
}


void search(ptrGame pGames)
{
int i, j;
ptrGame pRun = pGames;
string30 strWord;

if (pRun == NULL)
printf("Nothing to search.\n");
else
{
j = 0;
while(pRun!=NULL)
{
i = 0;
puts(pRun->strCategory[j][i]);
pRun = pRun->pLink;
i++;
j++;
}

pRun = pGames;
printf("Enter the category you want to search: \n");
scanf("%s",strWord);

if (pRun == NULL)
printf("Nothing to search.\n");
else
{
while(pRun != NULL)
{
if (strcmp(strWord, pRun->strCategory) == 0)
{
printf("Category: %s\n", pRun->strCategory);

for(i=0; i != 5; i++ )
{
printf("Question: %s\n", pRun->strQuestion[i]);
printf("Answer: %s \n", pRun->strAnswer[i]);
printf("Value: %s \n", pRun->strValue[i]);
}
}
pRun = pRun->pLink;
}
}
}
}

I keep on getting errors that passing argument are from different pointer types. What to do I do now?
 
Old 12-02-2009, 03:28 AM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
The errors are mostly because the code is not careful about how many levels the arrays have. If you declare something like:

Code:
typedef char string30[JEOPARDY+1] ;
...
string30 strCategory[5];
then you have an array of array of chars. So if you dereference it as strCategory[j][i], you end up with a char, which you cannot pass to a function that expects a 'char *'. Likewise, strCategory cannot be passed to a function that expects a 'char *', because it has not been dereferenced at all. Those are the causes of the first two errors; the remainder are similar.

I won't go into the difference between a 'char *' and an 'array of char' here because it may cause confusion (and isn't relevant to your errors).

(incidentally, if you put your code inside CODE tags in the post, it will retain the indenting)

Last edited by neonsignal; 12-02-2009 at 06:37 AM.
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Free Software for All Russian Schools in Jeopardy LXer Syndicated Linux News 0 11-16-2009 07:10 AM
LXer: Dell in Jeopardy with their Red Hat and Oracle Partnership LXer Syndicated Linux News 0 01-17-2006 12:31 PM
LXer: Jeopardy in the Dell-Red Hat-Oracle Partnership LXer Syndicated Linux News 0 01-17-2006 12:16 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration