Advertisement
Guest User

Untitled

a guest
Jan 12th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct Car{
  5. float capacityL;
  6. char *Brand;
  7. int Seats;
  8. struct Car *next;
  9. };
  10. struct Car *Listhead=NULL;
  11. void addCar();
  12. void printAndRemoveAllCars();
  13.  
  14. int main()
  15. {
  16. char choose;
  17. printf(" Enter a character : n or q \n");
  18. scanf(" %c",&choose);
  19. while(choose!='q'){
  20. addCar();
  21. printf("Enter 'p' for next point or 'q' for displaying all points \n");
  22. scanf(" %c",&choose);
  23.  
  24. }
  25. printAndRemoveAllCars();
  26. return 0;
  27. }
  28.  
  29. void addCar(){
  30. struct Car *temp = (struct Car*)malloc(sizeof(struct Car*));
  31. float cap;
  32. char brand[20];
  33. int seats;
  34. printf("Please enter the capacity in liters \n");
  35. scanf(" %f",&cap);
  36. printf("Please enter the brand name \n");
  37. scanf(" %c",&brand);
  38. printf("Please enter number of seats \n");
  39. scanf(" %d",&seats);
  40. temp->capacityL = cap;
  41. temp->Brand = brand;
  42. temp->Seats= seats;
  43. temp->next = Listhead;
  44. Listhead= temp;
  45. }
  46.  
  47. void printAndRemoveAllCars()
  48. {
  49. struct Car *temp;
  50. if(Listhead==NULL ){
  51. printf("There are no elements in the Stack! \n");
  52. }else{
  53. temp= Listhead;
  54. Listhead = Listhead ->next;
  55. printf(" Brand : %c /t capacity : %f /t numberofseats: %d \n",temp->Brand,temp->capacityL,temp->Seats);
  56. free(temp);
  57.  
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement