0

Hello All,

i have written a program to read data of Persons from a file and fill the data into a dynamically created array of Persons.
i am geting error in line 28
plz help

the 1.txt file can be assumed as:(first line is the no of persons, then names of persons are given with age separated by a dot)

3
abcxyx.10
aadd.12
sda.44


regards

#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
using namespace std;

struct Person
{
    char* name[25];
    int age;
};

int main()
{
    int size;
    Person* PersonPointer=0;
    ifstream fin;
    fin.open("1.txt");
    if(fin.is_open())
    {
        cout << "File opened!";
        fin >> size;
        PersonPointer = new Person[size];
        char temp[25]={'\0'};
        for(int i=0; i<size; i++)
        {
            fin.getline (temp, '.');
            strcpy(PersonPointer.name, temp);
            //PersonPointer.name = temp;
            fin >> PersonPointer[i].age;
        }
    }
    else cout << "error in opening file";
}
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by ravenous
0

I think that line 29 should be strcpy(PersonPointer[i].name, temp); Instead of strcpy(PersonPointer.name, temp);

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.