I have to use pointers in this program. I am trying to make 2 array's where one pulls data from a txt file and the other array copies the first array and fills in the rest of the space with 0's. I also need these to be happening in functions and not in main
So far my code is this: (I'd put less but I don't know where the problem is)
#include <iostream>
#include <fstream>
using namespace std;
void pullData(int* array, int fSIZE);
void doubledArray(int* array, int fSIZE, int aSIZE);
void arrayPrint(int* array, int fSIZE);
void inputCommand(int &userInput);
int main(){
int userInput = 51;
inputCommand(userInput);
const int SIZE = userInput;
const int SIZE2 = userInput * 2;
int array2[SIZE2];
int array[SIZE];
pullData(array, SIZE);
arrayPrint(array, SIZE);
cout << endl << endl;
doubledArray(array2, SIZE2, SIZE);
arrayPrint(array2, SIZE2);
return 0;
}
void pullData(int* array, int fSIZE){
string inFileName = "data.txt";
ifstream inFile;
inFile.open(inFileName.c_str());
if(inFile.is_open()){
for(int counter = 0; counter < fSIZE; counter++){
inFile >> array[counter];
}
}
}
void doubledArray(int* array, int fSIZE, int aSIZE){
string inFileName = "data.txt";
ifstream inFile;
inFile.open(inFileName.c_str());
if(inFile.is_open()){
for(int counter = 0; counter < aSIZE; counter++){
inFile >> array[counter];
}
}
for(int counter = 0; counter < fSIZE; counter++){
array[counter] = 0;
}
}
void arrayPrint(int* array, int fSIZE){
for(int counter = 0; counter < fSIZE; counter++){
cout << array[counter] << "\n";
}
}
void inputCommand(int &userInput){
while(userInput < 0 || userInput > 50){
cout << "Enter a number between 0-50: \n";
cin >> userInput;
if(userInput < 0 || userInput > 50){
cout << "Invalid input, please try again.\n\n";
}
}
}
I want to be getting:
0
1
2
3
4
0
1
2
3
4
0
0
0
0
0
but I'm currently getting:
0
1
2
3
4
0
0
0
0
0
0
0
0
0
0