Witam,
Mam taki problem. Stworzyłem strukturę danych. Wybieram ile osób chcę przypisać i wprowadzam dane. Potem chce je wyświetlić i tutaj zaczyna się problem.
main.cpp
#include "funkcje.h"
sOsoba *student = 0;
int n;
int main()
{
while(1)
{
wyswietl_menu();
char a;
a=_getch();
switch(a)
{
case '1':
{
cout<<"Ile osob chcesz wprowadzic?"<<endl;
cin>>n;
student = new sOsoba[n];
wprowadz_dane(student,n);
system("pause");
system("cls");
break;
}
case '2':
{
wyswietl_dane(student, n);
system("pause");
system("cls");
break;
}
}
}
funkcje.cpp
#include "funkcje.h"
sOsoba student;
void wyswietl_menu()
{
cout<<"Menu:"<<endl;
cout<<"1. Wprowadz dane osob"<<endl;
cout<<"2. Wyswietl dane osob"<<endl;
cout<<"3. Szukaj osobe"<<endl;
cout<<"X. Wyjscie"<<endl;
}
void wprowadz_dane(sOsoba *student, int n)
{
for(int a=0; a<n; a++)
{
cout<<"Wprowadz dane " <<a+1<< " osoby"<<endl;
cout<<"Podaj imie"<<endl;
cin>>student->imie,20;
cout<<"Podaj nazwisko"<<endl;
cin>>student->nazwisko,20;
}
}
void wyswietl_dane(sOsoba *student, int n)
{
for(int a=0; a<n; a++)
{
cout<<student[a].imie<<endl;
cout<<student[a].nazwisko<<endl;
}
}
funkcje.h
#ifndef _naglowki_h
#define _naglowki_h
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <conio.h>
using namespace std;
struct sOsoba
{
char imie[20];
char nazwisko[20];
};
void wyswietl_menu();
void wprowadz_dane(sOsoba *student, int n);
void wyswietl_dane(sOsoba *student, int n);
#endif