|
#1
|
|||
|
|||
C Programming Halp! :)
BOOLEAN SequentialSearch(ARRAY_LIST *plist, YEAR targetYear, int *loc)
{ int i; /* loop control variable */ int numFound; /* counts how many found */ BOOLEAN found; /* return value TRUE if success FALSE if not */ numFound = 0; /* set to none in the beginning */ found = FALSE; /* initial setting until a record is found */ /* search through the array list for targets */ for(i = 0; i < plist->count; i++) { if (EQ(targetYear, plist->car[i].year)) /* target year is found */ { loc = loc; numFound++; /* add one to the count */ /* ******** HERE IS WHERE YOU WILL WANT TO HANDLE DISPLAYING THE CAR RECORD. EITHER DIRECTLY, OR BY CALLING A FUNCTION TO DO IT ********* */ found = TRUE; /* successfully found at least one record */ } } printf("\n\n %d record(s) found that match\n", numFound); i = 0; /* reset value of i */ return found; } This is the function I am calling... the only problem is I don't know what to send it exactly. Who wants to help? [img]/images/graemlins/smile.gif[/img] |
#2
|
|||
|
|||
Re: C Programming Halp! :)
This looks suspiciously like homework. Unless... you work for a car dealership?
|
#3
|
|||
|
|||
Re: C Programming Halp! :)
Its a program assignment... about 1/15th of it. It is an online class so I don't really know how to find my answers out...
|
#4
|
|||
|
|||
Re: C Programming Halp! :)
how much money are you shipping to my FTP account if I help?
|
#5
|
|||
|
|||
Re: C Programming Halp! :)
[ QUOTE ]
how much money are you shipping to my FTP account if I help? [/ QUOTE ] $5? I R BUSTO! EDIT: and a pic of my penis |
#6
|
|||
|
|||
Re: C Programming Halp! :)
post your source in |code| |/code| tags so the array indexing doesn't turn into italics
|
#7
|
|||
|
|||
Re: C Programming Halp! :)
And so that there's some [censored] indentation
|
#8
|
|||
|
|||
Re: C Programming Halp! :)
<font class="small">Code:</font><hr /><pre>
#define YEAR int #define EQ(a, b) ((a) == (b)) typedef struct { char make[50]; char model[50]; YEAR year; } CAR; typedef struct { int count; CAR car[20]; } ARRAY_LIST; typedef enum boolean {FALSE, TRUE} BOOLEAN; ARRAY_LIST carlist = {5, { {"Dodge", "Dodge model", 1985}, {"Chevrolet", "Chevrolet model", 1990}, {"Cadillac", "Cadillac model", 2000}, {"BMW", "M5", 2003}, {"Porsche", "Carrera", 2007} } }; BOOLEAN SequentialSearch(ARRAY_LIST *plist, YEAR targetYear, int *loc) { int i; /* loop control variable */ int numFound; /* counts how many found */ BOOLEAN found; /* return value TRUE if success FALSE if not */ numFound = 0; /* set to none in the beginning */ found = FALSE; /* initial setting until a record is found */ /* search through the array list for targets */ for(i = 0; i < plist->count; i++) { if (EQ(targetYear, plist->car[i].year)) /* target year is found */ { loc = loc; numFound++; /* add one to the count */ /* ******** HERE IS WHERE YOU WILL WANT TO HANDLE DISPLAYING THE CAR RECORD. EITHER DIRECTLY, OR BY CALLING A FUNCTION TO DO IT ********* */ printf("%s - %s - %d\n", plist->car[i].make, plist->car[i].model, plist->car[i].year); found = TRUE; /* successfully found at least one record */ } } printf("\n\n %d record(s) found that match\n", numFound); i = 0; /* reset value of i */ return found; } void main() { BOOLEAN found; int loc; found = SequentialSearch(&carlist, 2007, &loc); } </pre><hr /> Try to understand what the code does before you hand it in [img]/images/graemlins/smile.gif[/img] |
|
|