Witam, mam problem z funkcją odczyt w tym programie:
#include <stdio.h>
#include <stdlib.h>
#define SWG 3
#define MAXN 20
#define MAXI 20
#define MAXO 100
struct student {
char nazwisko[MAXN];
char imie[MAXI];
unsigned short int wiek;
unsigned short int oceny_proc[MAXO];
};
void zapis (struct student *gr) {
int n;
FILE *plik=fopen("student.txt", "a+");
for (n=0; n<SWG; n++) {
fprintf (plik,"%s %s \n", gr[n].nazwisko, gr[n].imie);
}
}
void odczyt (struct student *gr) {
char nazwa[20];
FILE *plik;
printf("Podaj nazwe pliku: ");
gets(nazwa);
while(getchar()!='\n') {}
printf(nazwa);
plik=fopen(nazwa, "a+");
if ((plik)==NULL) {printf("Plik nie istnieje\n");}
}
void czytaj(struct student *gr){
int i;
for (i=0; i<SWG; i++){
printf("podaj nazwisko studenta %i\n", i+1);
gets(gr[i].nazwisko);
printf("podaj imie studenta %i\n", i+1);
gets(gr[i].imie);
}
}
void wypisz(struct student *gr){
int i;
for (i=0; i<SWG; i++){
printf("nazwisko studenta %i to %s\n", i, gr[i].nazwisko);
printf("imie studenta %i to %s\n", i, gr[i].imie);
}
}
int main()
{
int f, q;
struct student grupa[SWG];
///////////////////MENU
printf("Chcesz stworzyc nowy plik czy otworzyc istniejacy ? (1-nowy, 2-nadpisywanie)");
scanf("%d", &q);
if (q==1){
while (f!=10){
printf("'1' - wpisywanie studentow\n'2' - zapis\n");
scanf("%d", &f);
while(getchar()!='\n') {}
switch(f){
case 1: czytaj(grupa); break;
case 2: {
zapis(grupa); printf("Dane zapisano\n"); break;}
}
}
}
if (q==2){
odczyt(grupa);
while (f!=10){
printf("'1' - wpisywanie studentow\n'2' - zapis\n");
scanf("%d", &f);
while(getchar()!='\n') {}
switch(f){
case 1: czytaj(grupa); break;
case 2: {
zapis(grupa); printf("Dane zapisano\n"); break;}
}
}
}
system("pause");
return 0;
}
Cały czas wyświetla mi się, że plik nie istnieje, będę wdzięczny za pomoc