void testCreatePet() { Pet *p = createPet(1, "Bird", "Papagal", 200); assert(getId(p)==1); assert(strcmp(getType(p),"Bird")==0); assert(strcmp(getSpecies(p),"Papagal")==0); assert(getPrice(p)==200); distrugePet(p); }
int main (int argc, char * argv[]) { FILE * filePtr; struct Pet * * petArray; struct Pet * fastestPet; struct Pet * slowestPet; int i; char nameBuffer[20]; char breedBuffer[10]; double animalSpeed; char junk[50]; if (argc != 2) { printf("not enough parameters\n"); exit(0); } filePtr = fopen(argv[1], "r"); petArray = createArray(SIZE); for (i=0;i<SIZE; i++) { fscanf(filePtr,"%s%s%lf", nameBuffer, breedBuffer, &animalSpeed); petArray[i] = createPet(nameBuffer, breedBuffer, animalSpeed); fgets(junk, 50, filePtr); //to get rid of new line } fastestPet = findFastest(petArray, SIZE); slowestPet = findSlowest(petArray, SIZE); printf("The fast pet is: "); printPet(fastestPet); printf("\n"); printf("The slow pet is: "); printPet(slowestPet); printf("\n"); printf("Here is the whole array: \n"); printArray(petArray, SIZE); printf("\n"); freeArrayElements(petArray, SIZE); return 0; }
/** * Creaza o copie */ void* copyPet(void* p) { Pet* pet = (Pet*) p; return createPet(pet->id, pet->type, pet->species, pet->price); }