Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //lab 11.2, 11.3 -> 11 decembrie 2019
- #include <stdio.h>
- #include <stdlib.h>
- struct shopItem
- {
- char *name;
- int amount;
- } items[100], citems[100];
- int main()
- {
- items[0].name = "ciocolata";
- items[0].amount = 100;
- items[1].name = "capsuni";
- items[1].amount = 200;
- items[2].name = "haribo";
- items[2].amount = 40;
- FILE *f;
- f = fopen("date.txt", "r+");
- if (f==NULL)
- printf("asdad");
- for(int i=0; i<3; i++)
- fprintf(f, "%s %d\n", items[i].name, items[i].amount);
- rewind(f);
- for(int i=0; i<3; i++)
- {
- citems[i].name = (char*)malloc(100);
- fscanf(f, "%s", citems[i].name), fscanf(f, "%d", &citems[i].amount);
- }
- //fprintf("%d", fclose(f));
- int a = fclose(f);
- printf("%d", a);
- FILE *g;
- g = fopen("datesort.txt", "r+");
- if(g==NULL)
- printf("Asdasda");
- for(int i=0; i<3; i++)
- fprintf(g, "%s %d\n", citems[i].name, citems[i].amount);
- fclose(g);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement