I'm getting the same very large number for item and for each element in the array after that for loop is done. Why am i not pulling the 6 numbers from my input file? Thanks.
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main(int argc, char *argv[])
{
/* Extract value for # of elements in array */
int i;
sscanf (argv[2], "%d", &i);
// printf("i is %d\n", i);
/* Create Input and Output Streams */
ifstream fin;
ofstream fout;
/* Oprn Input and Output Streams */
fin.open("numlist.dat");
fout.open("numlist.dat");
/* Tests to ensure files opened */
if(fin.fail())
{
cerr << "Input did not open\n";
exit(2);
}
if(fout.fail())
{
cerr << "Output file did not open\n";
exit(2);
}
/* Construct New Array */
float *floatArray= new float[i];
/* Put numbers from list into array */
float item;
int j=0;
// printf("Put Numbers from list into array\n");
for (j=0; j<i;j++)
{
fin >> item;
printf("item is %f\n", item);
floatArray[j]=item;
printf("floatArray[%d] is %f\n", j, floatArray[j]);
}
getchar();
}