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>
usingnamespace std;
int main(){
char input[5459];
char output[1321] = { 0 };//initalize all values to 0
ifstream infile8("input.txt");//input file
ofstream fout("output.txt");//output file
int i;
while (infile8.getline(input, sizeof(input))){
//while (!infile8.eof()){//I previously had this but was informed it was wrong.
//When I did have the above it ran infinitely, and the below cout printed "\277"
//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;
}
When I tried it with a random small file (3 lines, a dozen chars of gibberish on each) it wrote +2 3 times in my output file. When I tried it with my large file, it never enters the loop.