Помогите найти ошибку в коде
Подскажите в чем ошибка.
#include <iostream>
#include <string.h>
using namespace std;
struct Data
{
int year;
char month[10];
char name [15];
char surname [15];
char secondname [15];
char street [20];
int home;
int apartment;
};
int main()
{
setlocale(LC_ALL, "rus");
Data *p = new Data[1];
int var = 1;
int size = 1;
while (var)
{
if(size == 1)
{
cout << "Имя: ";
cin >> p[size-1].name;
cout << "Фамилия: ";
cin >> p[size-1].surname;
cout <<"Отчество: ";
cin >> p[size-1].secondname;
cout <<"Месяц поступления на работу: ";
cin >>p[size-1].month;
cout << "Год поступления на работу: ";
cin >> p[size-1].year;
cout <<"Улица: ";
cin >> p[size-1].street;
cout <<"Дом: ";
cin >> p[size-1].home;
cout <<"Квартира: ";
cin >> p[size-1].apartment;
cout << "Элементы структуры объекта Р: " << p[size-1].name << " " << p[size-1].surname <<" " <<p[size-1].secondname <<" " <<p[size-1].month <<" " <<p[size-1].year <<" " <<p[size-1].street <<" " <<p[size-1].home <<" " <<p[size-1].apartment << ";n";
}
else//size > 1
{
Data *copy = new Data [size-1];
for(int i = 0; i < size-1; i++)
{
strcpy_s(p.name, copy.name);
strcpy_s(p.surname, copy.surname);
strcpy_s(p.secondname, copy.secondname);
strcpy_s(p.month, copy.month);
p.year = copy.year;
strcpy_s(p.street, copy.street);
p.home = copy.year;
p.apartment = copy.apartment;
}
delete [] p;
p = new Data[size];
for (int i = 0; i < size-1; i++)
{
strcpy_s(p.name, copy.name);
strcpy_s(p.surname, copy.surname);
strcpy_s(p.secondname, copy.secondname);
strcpy_s(p.month, copy.month);
p.year = copy.year;
strcpy_s(p.street, copy.street);
p.home = copy.year;
p.apartment = copy.apartment;
}
delete [] copy;
cout << "Имя: ";
cin >> p[size-1].name;
cout << "Фамилия: ";
cin >> p[size-1].surname;
cout <<"Отчество: ";
cin >> p[size-1].secondname;
cout <<"Месяц поступления на работу: ";
cin >>p[size-1].month;
cout << "Год поступления на работу: ";
cin >> p[size-1].year;
cout <<"Улица: ";
cin >> p[size-1].street;
cout <<"Дом: ";
cin >> p[size-1].home;
cout <<"Квартира: ";
cin >> p[size-1].apartment;
for (int i = 0; i < size; i++)
{
cout << i << "-е элементы структуры объекта Р: " << p.name << " " << p.surname <<" " <<p.secondname <<" " <<p.month <<" " <<p.year <<" " <<p.street <<" " <<p.home <<" " <<p.apartment << ";n";
}
}
size++;
cout << "nВнести еще данные - 1, выход - 0: ";
cin >> var;
while(var != 0 && var != 1)
{
cout << "Ошибка ввода!n";
cout << "nВнести еще данные - 1, выход - 0: ";
cin >> var;
}
}
delete [] p;
}
Код:
p.name
Делай так же, как и выше у тебя же в коде:
Код:
for(int i = 0; i < size-1; i++)
{
strcpy_s(p[i].name, copy[i].name);
strcpy_s(p[i].surname, copy[i].surname);
strcpy_s(p[i].secondname, cop[i]y.secondname);
strcpy_s(p[i].month, copy[i].month);
p[i].year = copy[i].year;
strcpy_s(p[i].street, cop[i]y.street);
p[i].home = copy[i].year;
p[i].apartment = copy[i].apartment;
}
{
strcpy_s(p[i].name, copy[i].name);
strcpy_s(p[i].surname, copy[i].surname);
strcpy_s(p[i].secondname, cop[i]y.secondname);
strcpy_s(p[i].month, copy[i].month);
p[i].year = copy[i].year;
strcpy_s(p[i].street, cop[i]y.street);
p[i].home = copy[i].year;
p[i].apartment = copy[i].apartment;
}