Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.37 KB | None | 0 0
  1. /*#include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. struct Car{
  5.  
  6.     int ID;
  7.     char brand[10];
  8.     char model[10];
  9.     char *new;
  10.  
  11. }ca1, car2; cars[2];
  12.  
  13. struct Car car1;
  14. car1.price = 25000;
  15. car car2;
  16. car2.price = 30000;
  17.  
  18. Car car1,car2;
  19. car1.ID..
  20. cars[0] = car1;
  21. cars[1] = car2;
  22.  
  23. cars[0].price = ...
  24. strcpy(cars[0].brand, "BMW")
  25.  
  26. struct Car cars[2];
  27.  
  28. car1->new= (char*)malloc(20); - pri ukazateli e sus strelka vmesto (.)
  29. -----
  30.     struct Birthday *people;
  31.  
  32.     *people=(struct Birthday*)malloc(sizeof(struct Birthday)*2);
  33. struct Car{
  34.  
  35.     int ID;
  36.     char brand[10];
  37.     char model[10];
  38.     char *new;
  39.  
  40. }*cars;
  41. struct Car *cars;
  42. *cars=(struct Car*)malloc(sizeof(structCar)*5);
  43.  
  44.     person1.date = 12;
  45.     strcpy(person1.month, "September");
  46.     person1.year = 1999;
  47.     person2.date = 1;
  48.     strcpy(person2.month, "April");
  49.     person2.year = 1992;
  50.  
  51.  
  52. #include<stdio.h>
  53. #include<stdlib.h>
  54. #include<string.h>
  55.  
  56. struct Birthday{
  57.    
  58.     int date;
  59.     char month[10];
  60.     int year;
  61.  
  62. }*people;
  63.  
  64. int main(){
  65.  
  66.     int i=0;
  67.     struct Birthday person1, person2;
  68. //  struct Birthday *people;
  69.  
  70.     people=(struct Birthday*)malloc(sizeof(struct Birthday)*2);
  71.    
  72.     person1.date = 12;
  73.     strcpy(person1.month, "September");
  74.     person1.year = 1999;
  75.     person2.date = 1;
  76.     strcpy(person2.month, "April");
  77.     person2.year = 1992;
  78.    
  79.     people[0] = person1;
  80.     people[1] = person2;
  81.  
  82.     printf("Person 1 birthday is on: %d %s %d\n", person1.date, person1.month, person1.year);
  83.     printf("Person 2 birthday is on: %d %s %d\n", person2.date, person2.month, person2.year);
  84.    
  85.  
  86.     return 0;
  87. }
  88. */
  89.  
  90. #include<stdio.h>
  91. #include<stdlib.h>
  92. #include<string.h>
  93.  
  94. struct Person_Information{
  95.    
  96.     struct Birthday birthday;
  97.     struct Address address;
  98.  
  99. }person1, person2, read_person1, read_person2;
  100.  
  101. struct Birthday{
  102.    
  103.     int date;
  104.     char month[10];
  105.     int year;
  106.  
  107. };
  108.  
  109. struct Address{
  110.    
  111.     char country[10];
  112.     char city[10];
  113.     char street[30];
  114.  
  115. };
  116.  
  117.  
  118. int main()
  119. {
  120.     typedef struct Birthday Birthday;
  121.    
  122.    
  123.     FILE *fp;
  124.     if((fp = fopen("file.bin", "wb")) == NULL){
  125.         printf("Error");
  126.     }
  127.     person1.birthday.date = 12;
  128.     strcpy(person1.birthday.month, "September");
  129.     person1.birthday.year = 1999;
  130.     strcpy(person1.address.country, "Bulgaria");
  131.     strcpy(person1.address.city, "Sofia");
  132.     strcpy(person1.address.street, "Vladichina livada");
  133.     person2.birthday.date = 12;
  134.     strcpy(person2.birthday.month, "September");
  135.     person2.birthday.year = 1999;
  136.     strcpy(person2.address.country, "Bulgaria");
  137.     strcpy(person2.address.city, "Plovdiv");
  138.     strcpy(person2.address.street, "Hristo Botev");
  139.  
  140.     fwrite(&person1, 1, sizeof(Birthday), fp);
  141.     fwrite(&person2, 1, sizeof(Birthday), fp);
  142.     fclose(fp);
  143.  
  144.     if((fp = fopen("file.bin", "rb")) == NULL){
  145.         printf("Error");
  146.     }
  147.  
  148.     fread(&read_person1, 1, sizeof(Birthday), fp);
  149.     fread(&read_person2, 1, sizeof(Birthday), fp);
  150.     printf("Personal Information\n");
  151.     printf("Person 1:\n Birthday: %d %s %d\n Address: %s %s %s\n",read_person1.birthday.date, read_person1.birthday.month, read_person1.birthday.year, read_person1.address.country, read_person1.address.city,read_person1.address.street);
  152.     printf("Person 2:\n Birthday: %d %s %d\n Address: %s %s %s\n",read_person2.birthday.date, read_person2.birthday.month, read_person2.birthday.year, read_person2.address.country, read_person2.address.city,read_person2.address.street);
  153.     fclose(fp);
  154.    
  155.     return 0;
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement