Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*#include<stdio.h>
- #include<stdlib.h>
- struct Car{
- int ID;
- char brand[10];
- char model[10];
- char *new;
- }ca1, car2; cars[2];
- struct Car car1;
- car1.price = 25000;
- car car2;
- car2.price = 30000;
- Car car1,car2;
- car1.ID..
- cars[0] = car1;
- cars[1] = car2;
- cars[0].price = ...
- strcpy(cars[0].brand, "BMW")
- struct Car cars[2];
- car1->new= (char*)malloc(20); - pri ukazateli e sus strelka vmesto (.)
- -----
- struct Birthday *people;
- *people=(struct Birthday*)malloc(sizeof(struct Birthday)*2);
- struct Car{
- int ID;
- char brand[10];
- char model[10];
- char *new;
- }*cars;
- struct Car *cars;
- *cars=(struct Car*)malloc(sizeof(structCar)*5);
- person1.date = 12;
- strcpy(person1.month, "September");
- person1.year = 1999;
- person2.date = 1;
- strcpy(person2.month, "April");
- person2.year = 1992;
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- struct Birthday{
- int date;
- char month[10];
- int year;
- }*people;
- int main(){
- int i=0;
- struct Birthday person1, person2;
- // struct Birthday *people;
- people=(struct Birthday*)malloc(sizeof(struct Birthday)*2);
- person1.date = 12;
- strcpy(person1.month, "September");
- person1.year = 1999;
- person2.date = 1;
- strcpy(person2.month, "April");
- person2.year = 1992;
- people[0] = person1;
- people[1] = person2;
- printf("Person 1 birthday is on: %d %s %d\n", person1.date, person1.month, person1.year);
- printf("Person 2 birthday is on: %d %s %d\n", person2.date, person2.month, person2.year);
- return 0;
- }
- */
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- struct Person_Information{
- struct Birthday birthday;
- struct Address address;
- }person1, person2, read_person1, read_person2;
- struct Birthday{
- int date;
- char month[10];
- int year;
- };
- struct Address{
- char country[10];
- char city[10];
- char street[30];
- };
- int main()
- {
- typedef struct Birthday Birthday;
- FILE *fp;
- if((fp = fopen("file.bin", "wb")) == NULL){
- printf("Error");
- }
- person1.birthday.date = 12;
- strcpy(person1.birthday.month, "September");
- person1.birthday.year = 1999;
- strcpy(person1.address.country, "Bulgaria");
- strcpy(person1.address.city, "Sofia");
- strcpy(person1.address.street, "Vladichina livada");
- person2.birthday.date = 12;
- strcpy(person2.birthday.month, "September");
- person2.birthday.year = 1999;
- strcpy(person2.address.country, "Bulgaria");
- strcpy(person2.address.city, "Plovdiv");
- strcpy(person2.address.street, "Hristo Botev");
- fwrite(&person1, 1, sizeof(Birthday), fp);
- fwrite(&person2, 1, sizeof(Birthday), fp);
- fclose(fp);
- if((fp = fopen("file.bin", "rb")) == NULL){
- printf("Error");
- }
- fread(&read_person1, 1, sizeof(Birthday), fp);
- fread(&read_person2, 1, sizeof(Birthday), fp);
- printf("Personal Information\n");
- 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);
- 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);
- fclose(fp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement