Program się włącza, jednak problem polega na wyświetleniu "wartości" jak również adresu 'st.hobby[SLEN]' i 'ps->hobby[SLEN]' w funkcji display1 i 2
Oto kod programu:
#include <iostream>
const int SLEN = 30;
struct student
{
char fullname[SLEN];
char hobby[SLEN];
int ooplevel;
};
int getinfo (student pa[], int n);
void display1 (student st);
void display2 (const student *ps);
void display3 (const student pa[], int n);
int main()
{
std::cout << "Podaj wielkosc grupy: ";
int class_size;
std::cin >> class_size;
while(std::cin.get() != '\n')
continue;
student * ptr_stu = new student[class_size];
int entered = getinfo(ptr_stu, class_size);
for(int i=0; i < entered; i++)
{
display1(ptr_stu[i]);
display2(&ptr_stu[i]);
}
display3(ptr_stu, entered);
delete [] ptr_stu;
std::cout << "\n\nGotowe\n";
return 0;
}
int getinfo (student pa[], int n)
{
for(int i=0; i < n; i++)
{
std::cout << "Podaj nazwisko studenta: ";
std::cin >> pa[i].fullname[SLEN];
std::cout << "Podaj hobby student: ";
std::cin >> pa[i].hobby[SLEN];
std::cout << "Rok studiow: ";
std::cin >> pa[i].ooplevel;
}
std::cout << std::endl;
return n;
}
void display1 (student st)
{
std::cout << "\tWartosc\n" << st.fullname[SLEN] << "\n" << st.hobb
y[SLEN] << "\n" << st.ooplevel << "\n";
}
void display2 (const student * ps)
{
std::cout << "\tAdresy\n" << &ps->fullname[SLEN] << "\n" << &ps->h
obby[SLEN] << "\n" << &ps->ooplevel << "\n\n";
}
void display3 (const student pa[], int n)
{
std::cout << "\nAdresy pierwszych elementow struktury\n";
for(int i=0; i < n; i++)
std::cout << &pa[i].fullname[SLEN] << "\n" << &pa[i].hobb
y[SLEN] << "\n" << &pa[i].ooplevel;
}