Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct Car{
- float capacityL;
- char *Brand;
- int Seats;
- struct Car *next;
- };
- struct Car *Listhead=NULL;
- void addCar();
- void printAndRemoveAllCars();
- int main()
- {
- char choose;
- printf(" Enter a character : n or q \n");
- scanf(" %c",&choose);
- while(choose!='q'){
- addCar();
- printf("Enter 'p' for next point or 'q' for displaying all points \n");
- scanf(" %c",&choose);
- }
- printAndRemoveAllCars();
- return 0;
- }
- void addCar(){
- struct Car *temp = (struct Car*)malloc(sizeof(struct Car*));
- float cap;
- char brand[20];
- int seats;
- printf("Please enter the capacity in liters \n");
- scanf(" %f",&cap);
- printf("Please enter the brand name \n");
- scanf(" %c",&brand);
- printf("Please enter number of seats \n");
- scanf(" %d",&seats);
- temp->capacityL = cap;
- temp->Brand = brand;
- temp->Seats= seats;
- temp->next = Listhead;
- Listhead= temp;
- }
- void printAndRemoveAllCars()
- {
- struct Car *temp;
- if(Listhead==NULL ){
- printf("There are no elements in the Stack! \n");
- }else{
- temp= Listhead;
- Listhead = Listhead ->next;
- printf(" Brand : %c /t capacity : %f /t numberofseats: %d \n",temp->Brand,temp->capacityL,temp->Seats);
- free(temp);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement