#11
|
|||
|
|||
Re: C Programming Halp! :)
[ QUOTE ]
1. that is really [censored] ugly 2. do you really comment every [censored] line? 3. send it this [censored] ARRAY_LIST *plist, YEAR targetYear, int *loc [/ QUOTE ] 1. This is the problem I'm having... the professor created this and told us to use it... I could make my own but thats not allowed. 2. HELL NO 3. Well I'm not sure what those are. [img]/images/graemlins/smile.gif[/img] I'm supposed to use data from a .data file and send it to this function...but don't know what the first and last ones are... [img]/images/graemlins/frown.gif[/img] |
#12
|
|||
|
|||
Re: C Programming Halp! :)
[ QUOTE ]
3. Well I'm not sure what those are. [/ QUOTE ] Uh, read whatever intro to comp programming book you should have read? There are also plenty of webpages on the 'intertubes' that have programming examples, docs, etc. Anyone helping you with this is just putting a band aid on a gangrenous leg... edit: this was not meant to sound unduly harsh. If you don't know the requirements then talk to your prof. Then read basic programming book, then perhaps come back and ask a thoughtful question. As in a general, not specific to your homework assignment question. [img]/images/graemlins/smile.gif[/img] |
#13
|
|||
|
|||
Re: C Programming Halp! :)
[x] OP is going to fail.
|
#14
|
|||
|
|||
Re: C Programming Halp! :)
hmm, some sort of double post when trying to edit.
|
#15
|
|||
|
|||
Re: C Programming Halp! :)
$20 on tilt to anyone who helps me finish this thing. I'm just plain stupid I guess.
|
#16
|
|||
|
|||
Re: C Programming Halp! :)
[ QUOTE ]
I'm supposed to use data from a .data file and send it to this function...but don't know what the first and last ones are... [/ QUOTE ] They are pointers IIRC. Seriously, follow Leapfrog's advice and (re)read the documentation recommended for your course. |
#17
|
|||
|
|||
Re: C Programming Halp! :)
you're trying to print out every car in the .data file that has the same year as the year you're searching for.
somehow, you're going to need to get all the cars into an arraylist (not in this function), and then call this function when you want to print out all the cars with a specific year. plist is going to be the array with all the cars, targetYear is the year that you're going to be searching for, loc is going to be the location (index in plist) of the last car found with targetYear. (you can pass for example a loc=-1 value and if no cars are found, loc will remain -1, otherwise the last car with the targetYear found's location will be the new loc after you run the program). |
#18
|
|||
|
|||
Re: C Programming Halp! :)
btw, plist holds an array of "car". if your professor hasnt given you the skeleton for that class or the function to get the array list from the .data file, you have a long way to go
|
#19
|
|||
|
|||
Re: C Programming Halp! :)
[ QUOTE ]
btw, plist holds an array of "car". if your professor hasnt given you the skeleton for that class or the function to get the array list from the .data file, you have a long way to go [/ QUOTE ] I know I'm nit-picking hear, but it's C, not C++ or Java, so "car" would be a structure, not a class. |
#20
|
|||
|
|||
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] |
|
|