C ++ Urgent help with files !!! HWzone Forums
Skip to content
  • Create an account
  • About Us

    Hello Guest!

    Please note - in order to participate in our community, comment and open new discussions, you must join as a registered member.

    Our members enjoy many advantages, including the ability to participate in discussions, enjoy raffles and promotions for members of the site, and receive our weekly content directly by email.

    Do not like being harassed by email? You can register for the site but do not submit your registration to the weekly email updates.

C ++ Urgent help with files !!!

ח א

Recommended Posts

I created an array of structures that reads data from a file
Running error 'Data not read from file'
Here is the code
Big thanks to the helpers !!!


#pragma warning (suppress: 4996)

using namespace std;

int len ​​(struct PERSON p) {
    int leng = strlen (p.first);
    leng + = strlen (p.last);
    leng + = 4;
    return leng;

void fullName (char * p, struct PERSON & person) {
    char fullName [52];
    strcpy (person.first, fullName);
    strcat (fullName, "");
    strncat (fullName, person.middle, 1);
    strcat (fullName, "");
    strcat (fullName, person.last);
    p = fullName;

struct PERSON
    char first [25];
    char middle [25];
    char last [25];
    char * fullN;

int main () {
    struct PERSON * people;
    int num;
    cout << "enter num of persons" <
    cin >> num;
    while (num <0) {
        cout << "ERROR / n enter new num" << endl;
        cin >> num;
    people = new PERSON [num];
    ifstream inData;
    inData.open ("data.txt");
    if (! inData.is_open ()) {
        cerr << "Cannot open input file \ n";
        exit (EXIT_FAILURE);

    int i = 0;
    while (! inData.eof ()) {
        char str [100];
        inData >> people [i] .first;
        inData >> people [i] .middle;
        inData >> people [i] .last;
        people [i] .fullN = new char [len (people [i])];
        fullName (people [i] .fullN, people [i]);
        i + +;
    inData.close ();
    0 return;


Link to content
Share on other sites

Join the discussion

You can then join the discussion and then join our community. If you already have an account with us, please Log in now To comment under your username.
Note that: The comment will appear to the surfers after approval by the board management team.

Add a comment

×   The content pasted is with formatting.   Remove formatting

  Only 75 emoji are allowed.

×   Your link has been automatically assimilated.   Show as regular link

×   Your previous content has been automatically restored.   Clear all

×   You can not paste images directly. Upload or insert images from URL.


  • Latest news

  • Buzz-Zone: Everything hot on the net

  • Create new ...

At the top of the news:

new on the site