Complet exercici 3c
This commit is contained in:
parent
a15e818110
commit
7fb7c113fd
1 changed files with 39 additions and 1 deletions
|
@ -306,7 +306,45 @@ tApiError api_getVaccines(tApiData data, tCSVData *vaccines) {
|
|||
//////////////////////////////////
|
||||
// Ex PR1 3c
|
||||
/////////////////////////////////
|
||||
return E_NOT_IMPLEMENTED;
|
||||
|
||||
tApiError ret = E_NOT_IMPLEMENTED;
|
||||
tCSVEntry foundVaccine;
|
||||
tVaccineNode* currentVaccine;
|
||||
char buffer[FILE_READ_BUFFER_SIZE];
|
||||
char name[MAX_VACCINE_NAME_LEN];
|
||||
int required;
|
||||
int days;
|
||||
csv_init(vaccines);
|
||||
|
||||
currentVaccine = data.vaccines.first;
|
||||
|
||||
// Go through all nodes in vaccine list until current one is nothing
|
||||
while (currentVaccine != NULL) {
|
||||
csv_initEntry(&foundVaccine);
|
||||
|
||||
// Reuse previous function to get a vaccine by name and have it stored in a CSVEntry
|
||||
if (api_getVaccine(data,currentVaccine->vaccine.name,&foundVaccine) == E_SUCCESS) {
|
||||
|
||||
// Read vaccine info from getVaccine() method
|
||||
csv_getAsString(foundVaccine,0,name,MAX_VACCINE_NAME_LEN+1);
|
||||
required = csv_getAsInteger(foundVaccine,1);
|
||||
days = csv_getAsInteger(foundVaccine,2);
|
||||
|
||||
// Fill new csv string with format required
|
||||
sprintf(buffer,"%s;%d;%d",name,required,days);
|
||||
csv_addStrEntry(vaccines,buffer,VACCINE_TYPE_NAME);
|
||||
|
||||
ret = E_SUCCESS;
|
||||
}
|
||||
|
||||
// Clean up dynamic memory used
|
||||
csv_freeEntry(&foundVaccine);
|
||||
|
||||
// Point currentVaccine to next element to get forward in the loop
|
||||
currentVaccine = currentVaccine->next;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Get vaccine lots
|
||||
|
|
Reference in a new issue