Still working on this same problem. My assignment is to create a function that accepts an array as an argument and creates an array that is twice the size.
The full problem: "Write a function that accepts an int array and the array ’s size as arguments . The function should create a new array that is twice the size of the argument array . The function should copy the contents of the argument array to the new array , and initialize the unused elements of the second array with 0. The function should return a pointer to the new array . Demonstrate the function by using it in a main program that reads an integer N (that is not more than 50) from standard input and then reads N integers from a file named data into an array ."
I've been trying to get this to work for a few days now. I am completely stuck, hopeless, lost. I don't know what is wrong. One error I keep seeing is invalid conversion from int* to int.
//read the first N numbers from a file
#include <fstream>
using namspace std;
ifstream input("data.txt");
int N;
cout<<"Enter size: ";
cin>>N;
if(N < 0 || N > 50)
{
cout<<"Invalid number"<<endl;
return -1; //not successful
}
int array[N];
int count = 0;
while(count <= N)
{
input>>array[count];
count++;
}
Now, continue to expand the array as in the code above.