0

I am getting large (several MB) spreadsheets in txt form with way more information than I need. It is predictable. So I want to load up my input file, put the first line into an array of chars, pick out the few relevant pieces into an output array, copy the output array to a separate output file, and loop through for each line in the input.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(){

char input[5459];
char output[1321] = { 0 };//initalize all values to 0
ifstream infile8;//input file
infile8.open("input.txt");

ofstream fout("output.txt");//output file

int i;
while (infile8.getline(input, sizeof(input))){

    //cout << input[2] << " \n";
    output[0] = input[18];//transaction status
    //I select a bunch more info from the arrays here like above
    i = 0;
    while (i <= 1320){
        fout << output[i];
        i++;
    }
    fout << '\n';

    //output = { 0 };//reset output file
}

return 0;
}

It currently never enters the loop.

babno
  • 267
  • 2
  • 6
  • 15
  • One of your problems is here : infile8.getline(input, sizeof(infile8)); You want to use the size of the input as the maximum, not the size of ifstream class (not the size of the stream -- the size of the class in memory). infile8.getline(input, sizeof(input)); It isn't clear what your 'magic numbers' are meant to be either... 5459, 1321, 1320 – LawfulEvil May 29 '15 at 13:21
  • those numbers are the size of the files I am getting. The new file (input) is 5459 chars long for each line. The information I need (output) is 1321 chars long, and of course arrays start at 0 so the final place of output array is 1320. – babno May 29 '15 at 13:34
  • In addition to not reading the whole line (for the reason above) you've got an issue with the EOF(potentially based on the solution you got 'duplicated' to). – LawfulEvil May 29 '15 at 13:39

0 Answers0