#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
using namespace std;
struct student {
int nr_indeksu;
int nazwisko;
int ocena;
struct student *nast;
};
int main()
{ int a;
struct student *wsk = NULL;
struct student *glowa = NULL;
FILE *stream = fopen("dane.txt", "r");
if (stream == NULL)
{
cout<<"Nie udalo sie otworzyc pliku notatki.txt";
return 1;
}
cout<<"Plik otwarty pomyslnie!";
while (!feof( stream )) {
if (glowa == NULL)
glowa = wsk = (struct student*)malloc(sizeof(struct student));
else {
wsk->nast = (struct student*)malloc(sizeof(struct student));
wsk = wsk->nast;
}
fscanf(stream, "%s %s %s\n", wsk->nr_indeksu,wsk->nazwisko,wsk->ocena);
wsk->nast = NULL;
}
fclose(stream);
return 0;
}
Do oczytanie mam dane z pliku, natomiast to co napisałem nie działa. Jakieś sugestie?