0

im having a problem. everytime i try to give values to an array of struct from a function in a header file, my program stops working, and ends after windows tells me thar the program is not respoding. i coded a little example of the problem im having, so it can be read easier. it still crashes. everything is part of a console application project.

here´s the main.cpp file:

    #include <iostream>
    #include <cstdlib>
    #include <string.h>

    struct test{
    int number;
    char name[20];
    };

    #include "functions.h"

    using namespace std;

    int main()
    {
    test *arr[5];

    filleverything(*arr);

    return 0;
    }

And here´s the functions.h file:

    #ifndef FUNCTIONS_H_INCLUDED
    #define FUNCTIONS_H_INCLUDED
    #include <iostream>
    #include <cstdlib>
    #include <string.h>

    using namespace std;

    void filleverything(test *arr){
    int i;
        for(i=0;i<=5;i++){
            cout << endl << "Write a number: ";
            cin >> arr[i].number;
            cout << endl << "Write a name: ";
            cin >> arr[i].name;
        }
    }

this is a work for college, and we are not allowed to use global variables at all. also, the array has to be filled from the functions.h file using pointers, as im trying to do, with no success. could anyone help me?

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
Paulo
  • 79
  • 8
  • 1
    This looks more like C++ than C. I suggest losing the C tag. – e0k Dec 05 '16 at 00:36
  • @e0k: It does not just not look like C, this is **not** C. – too honest for this site Dec 05 '16 at 00:37
  • In C++, I think it's `` instead of ``. See also [Difference between and ?](http://stackoverflow.com/questions/9257665/difference-between-string-and-string-h). – e0k Dec 05 '16 at 00:38
  • `test *arr[5]; filleverything(*arr);` --> `test arr[5]; filleverything(arr);`, `for(i=0;i<=5;i++){` --> `for(i=0;i<5;i++){` – BLUEPIXY Dec 05 '16 at 00:38
  • @BLUEPIXY oh, just realized how this thing worked... 8 months for this and u just came and saved my life, thanks – Paulo Dec 05 '16 at 00:48

0 Answers0