mam kolejny problem mianowicie chodzi o odczytywanie z pliku cos nie dziala i jezeli ktos moglby cos podpowiedziec bylbym bardzo wdzieczny takze z zapisem mam drobny problem ogolnie dziala ale nie wiem jak zrobic zeby mozna bylo cos dopisac do juz istniejacych daneych jezeli ktos moglby co poradzic bylbym bardzo wdzieczny Pozdrawiam
#include"stdio.h"#include"stdlib.h"#include"math.h"#include"string"struct element{ int numer; char *autor; char *tytol; char *gatunek; struct element *next;};void wstaw(struct element **l, int n, char *a, char *t, char *g);void wypisz(struct element *l);struct element * dodaj();void odczyt(struct element *l);void zapis(struct element *l);main(){ int odp,koniec; odp=0; int k=0; struct element *lista; while(k==0){ printf("\n********************************************************\n"); printf("MENU \n"); printf("1. Dodaj \n"); printf("2. Wypisz \n"); printf("3. Odczyt \n"); printf("4. Zapis \n"); printf("5. Koniec \n"); printf("\n********************************************************\n"); printf("\n\n\n"); printf("Podaj numer operracji: "); scanf("%d", &odp); switch(odp) { case 1: lista=dodaj(); break; case 2: wypisz(lista); break; case 3: odczyt(lista); break; case 4: zapis(lista); break; case 5: k=1; } }}//******************************************************************************void wstaw(struct element **l, int n, char *a, char *t, char *g){ struct element * nowy; nowy = (struct element *)malloc(sizeof(struct element)); if(nowy == NULL) { printf("Not enough memory.\n"); exit( -1); } nowy->next = *l; nowy->numer = n; nowy->autor = a; nowy->tytol = t; nowy->gatunek = g; *l = nowy;};//******************************************************************************void wypisz(struct element *l){ struct element * wsk; for(wsk = l; wsk; wsk = wsk->next) { printf("\n"); printf("%i ", wsk->numer); printf(".\t"); printf("%s", wsk->autor); printf("\t"); printf("%s", wsk->tytol); printf("\t"); printf("%s", wsk->gatunek); printf("\n"); } };//******************************************************************************struct element * dodaj(){ struct element * wsk=NULL; int wart,i, ile; char *a, *t, *g; char temp[255], temp2[255], temp3[255]; printf("Podaj liczbe elementow do wstawienia:"); scanf("%i", &ile); for(i = 0; i < ile; i++) { printf("Podaj numer : "); scanf("%i", &wart); printf("\n"); printf("Podaj autora : "); gets(temp); gets(temp); printf("Podaj tytol : "); gets(temp2); printf("Podaj gatunek : "); gets(temp3); a = (char*)malloc((unsigned)strlen(temp)*sizeof(char)); t = (char*)malloc((unsigned)strlen(temp2)*sizeof(char)); g = (char*)malloc((unsigned)strlen(temp3)*sizeof(char)); strcpy(a,temp); strcpy(t,temp2); strcpy(g,temp3); printf("\n"); wstaw(&wsk,wart,a,t,g); } return wsk; };//******************************************************************************void zapis(struct element *l){ FILE *in, *out; struct element * wsk; int size; int i; i=0; for(wsk = l; wsk; wsk = wsk->next) { i++; } size=i; if((out = fopen("Biblioteka.TXT", "wt")) == NULL) { printf("Cannot open output file.\n"); exit(-1); } printf("Zapisuje do pliku wielkosc bazy\n"); fprintf(out, "%i ", size); printf("\n"); printf("Zapisuje dane do pliku:\n"); for(wsk = l; wsk; wsk = wsk->next) { fprintf(out, "%i ", wsk->numer); fprintf(out, "%s ", wsk->tytol); fprintf(out, "%s ", wsk->autor); fprintf(out, "%s ", wsk->gatunek); } printf("Dane zapisane\n"); fclose(out);}//******************************************************************************void odczyt(struct element *l){ FILE *in, *out; struct element * wsk; int size; int i; i=0; for(wsk = l; wsk; wsk = wsk->next) { i++; } size=i; if((out = fopen("Biblioteka.TXT", "wt")) == NULL) { printf("Cannot open output file.\n"); exit(-1); } printf("Odczytuje dane z pliku:\n"); for(wsk = l; wsk; wsk = wsk->next) { fscanf(in, "%i", wsk->numer); fscanf(in, "%s", wsk->tytol); fscanf(in, "%s", wsk->autor); fscanf(in, "%s", wsk->gatunek); fgetc(in); }}