Untitled
unknown
plain_text
a year ago
1.2 kB
7
Indexable
#include <stdio.h> #include <stdlib.h> struct student { char imie[25]; char nazwisko[50]; int nrind; }; void wprowadz_dane(struct student* st, int ilosc) { for (int i = 0; i < ilosc; i++) { printf("Podaj Imie: "); fflush(stdin); scanf("%s", st[i].imie); printf("Podaj Nazwisko: "); fflush(stdin); scanf("%s", st[i].nazwisko); printf("Podaj numer albumu: "); fflush(stdin); scanf("%d", &st[i].nrind); } } void wyswietl(struct student* st, int ilosc) { for (int i = 0; i < ilosc; i++) { printf("Dane studenta nr %d: \n", i+1); printf("Imie: %s, Nazwisko: %s, Nr Albumu: %d \n", st[i].imie, st[i].nazwisko, st[i].nrind); } } int main() { int ilosc; printf("Podaj ile studentow chcesz dodac: "); scanf("%d", &ilosc); struct student *tablica_studentow = malloc(ilosc * sizeof(struct student)); if (tablica_studentow == NULL) { fprintf(stderr, "Błąd alokacji pamięci.\n"); return 1; } wprowadz_dane(tablica_studentow, ilosc); wyswietl(tablica_studentow, ilosc); free(tablica_studentow); return 0; }
Editor is loading...
Leave a Comment