Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h> // for open()
- #include <errno.h> // for perror()
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <string.h> //for strcpy()
- #include <unistd.h> //for file write()
- struct Kivansag {
- double date;
- char name[100];
- char city[100];
- char address[100];
- char gift[100];
- };
- int main(){ //18
- //const char *array[] = {"almafa\n", "kortefa\n", NULL};
- int list_size = 0;
- FILE *list = fopen("kivansagok", "wb");
- struct Kivansag kivansag = {1000,"TestName", "TestCity", "TestAddress", "TestGift"};
- struct Kivansag kivansag2 = {2000,"TestName", "TestCity", "TestAddress", "TestGift"};
- ++list_size;
- ++list_size;
- struct Kivansag asd[2]= {kivansag, kivansag2};
- fwrite(&list_size, sizeof(list_size),1,list);
- fwrite(&asd, sizeof(asd),1,list);
- printf("%lu \n", sizeof(list));
- fclose(list);
- struct Kivansag test;
- struct Kivansag dsa[22];
- list_size = 0;
- list = fopen("kivansagok", "rb");
- fread(&list_size, sizeof(list_size), 1, list);
- fread(&dsa, sizeof(dsa), 1, list);
- fclose(list);
- printf("size: %d \n", list_size);
- printf("teszt: %f %s %s %s %s \n ",
- dsa[0].date,
- dsa[0].name,
- dsa[0].city,
- dsa[0].address,
- dsa[0].gift);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement