i have some problem and really don't know what to do, i will appreciate any help. I need to make program for adding new animals to linked list, but not adding and printing works the way it should.
#include <iostream>
usingnamespace std;
bool allocated=false;
struct pets{
int code, cost, delivery_date;
char name, type;
pets *next;
};
int register_new(pets *head, //potrebna glava liste
int code, int cost,
int delivery_date,
char* naziv, //passing chars to function has give me some troubles too so i'll ignore that 'till i make other things work
char* vrsta)
{
if (allocated==false) {
head->next=NULL;
allocated=true;
}
pets *current=head; //prvi element
while (current->next) //traženje elementa
current=current->next; //koji je zadnji u listi
pets *new_el=new pets; //incijaliziramo novi element u listi
current->next=new_el; //pokazivac *slijedeci (sada) predzadnjeg elementa pokazuje na novokreirani (koji je sada zadnji)
new_el->next=NULL; //a pokazivac novog elementa = NULL
new->code = code;
// strcpy((char*)novi->vrsta, vrsta); //type of pet
// strcpy((char*)novi->naziv, naziv); //name of pet
new_el->cost=cost;
new_el->delivery_date=delivery_date;
new_el->next=current->next;
current->next=new_el;
current=head->next;
while(current!=NULL && current->code!=code)
current=current->next;
if (current==NULL) //ako ova funkcija ne može naći zapis onda stvarno ne znam tko može
{
return 0;
}//check if adding new pet is succesfull
else
{
return 1;
}
}
void print(pets *head)
{
pets *current=head->next;
while(current){
cout << "\nSifra: " << current->code;
//cout << "\nVrsta: " << trenutni->vrsta;
//cout << "\nNaziv: " << trenutni->naziv;
cout << "\nCijena: " << current->name;
cout << "\nDatum dostave: " << current->delivery_date << "\n------------------------\n\n";
current=current->next; //pomicanje kroz listu
}
}