Witam próbowałem stworzyć w C liste studentów, ale przy wprowadzaniu samodzielnie kolejnych osób wszyscy przyjmują imię i nazwisko ostatnio wpisanej osoby(numer indeksu i srednia ocen zostają nienaruszone)
Prosze o pomoc i z góry dziekuje.
MAIN:
#include "funkcje.h"
int main()
{
int wybor;
const char imie[15];
const char nazwisko[15];
unsigned int indeks;
float srednia;
poczatek = 0;
dodaj("Beniamin","Idziak",11697,4.5);
dodaj("Ala","Makota",11698,4.9);
printf("-----------------------------------DZIEKANAT-----------------------------------");
for( ; ; )
{
printf("\nMENU:");
printf("\n1. Wyswietl studentow");
printf("\n2. Dodaj studenta");
printf("\n3. Usun studenta");
printf("\n4. Sortuj studentow");
printf("\n5. Wyszukaj studenta");
printf("\n6. Wyjdz");
printf("\nWYBIERZ: ");
scanf("%d", &wybor);
fflush(stdin);
switch(wybor)
{
case 1:
{
wyswietl();
break;
}
case 2:
{
printf("\nPodaj imie: ");
scanf("%s",imie);
printf("\nPodaj nazwisko: ");
scanf("%s",nazwisko);
printf("\nPodaj nr. indeksu: ");
scanf("%d",&indeks);
printf("\nPodaj srednia: ");
scanf("%f",&srednia);
fflush(stdout);
dodaj(imie,nazwisko,indeks,srednia);
break;
}
}
}
return 0;
}
FUNKCJE.C:
#include "funkcje.h"
struct student* nowy(char* imi, char* naz, unsigned int ind, float sr)
{
struct student* nowys = (struct student*)malloc(sizeof(struct student));
nowys->imie = imi;
nowys->nazwisko = naz;
nowys->indeks = ind;
nowys->srednia = sr;
nowys->nast = 0;
return nowys;
}
void dodaj(char* imi, char* naz, unsigned int ind, float sr)
{
struct student* bufor = poczatek;
struct student* nowys = nowy(imi,naz,ind,sr);
if(poczatek == 0)
{
poczatek = nowys;
return;
}
while(bufor->nast != NULL)
{
bufor = bufor->nast;
}
bufor->nast = nowys;
}
void wyswietl()
{
struct student* bufor = poczatek;
printf("STUDENCI:\n");
while(bufor != NULL)
{
printf("IMIE:%10s NAZWISKO:%10s NR.INDEK5SU:%5d SREDNIA:%0.1f\n",bufor->imie, bufor->nazwisko, bufor->indeks, bufor->srednia);
bufor = bufor->nast;
}
}
FUNKCJE.H:
#ifndef FUNKCJE_H
#define FUNKCJE_H
#include <stdio.h>
#include <string.h>
struct student
{
char* imie;
char* nazwisko;
unsigned int indeks;
float srednia;
struct student* nast;
}*poczatek;
struct student* nowy(char* imi, char* naz, unsigned int ind, float sr);
void dodaj(char* imi, char* naz, unsigned int ind, float sr);
void wyswietl();
#endif