Hi, i am making a program that contains an integer array of an unknown size.The user is prompted to enter numbers into the array,and press 'x' to exit.
What i am going to do then,is to pass the array from the main into a class which contains another array,but before i do that i wanted to allocate the required space for this array in my class.
Here is what i have done so far(i have made a small test program with a function instead of included class files)
#include <iostream>
#define MAX_SIZE 50
using namespace std;
void Malloc(int _array[]);
main(){
int array[MAX_SIZE] = {};
char exit;
// enter numbers into an array
for(int i = 0; i < MAX_SIZE; i++)
{
// if user enters x program will stop input to array.
if(exit == 'x')
{
break;
}
cin >> array[i];
}
for(int i = 0; array[i] != '\0'; i++)
{
cout << array[i];
}
Malloc(array[]);
}
void Malloc(int _array) {
int size;
int classArray[];
// Find the size of the array passed in as an argument.
for(size = 0; _array[size] != '\0'; size++);
classArray = (char*)malloc(size+1);
for(int i = 0; _array[i] != '\0'; i++)
{
classArray[i] = _array[i];
}
}
Does anyone have any suggestions as to what im doing wrong?Any help is appreciated.