Save Chart to File
Apr 12, 2015 at 10:44pm UTC
How would I syntactically create a function that asks a user for a file name, and then saves a chart (previously opened in the program) to that file name.
This is what I have so far, but the file does not recreate the original file format like it is supposed to do.
Original readChart function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
void readChart(char chart[ROWS][COLS])
{
int rowNumber;
char seat1, seat2, seat3, seat4;
while (!ins.eof())
{
ins >> rowNumber;
ins >> seat1 >> seat2 >> seat3 >> seat4;
chart[rowNumber - 1][0] = seat1;
chart[rowNumber - 1][1] = seat2;
chart[rowNumber - 1][2] = seat3;
chart[rowNumber - 1][3] = seat4;
}
}
function I am trying to write a new file with (need help with this one):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
void saveSeatChartToFile()
{
int rowNumber;
char seat1, seat2, seat3, seat4;
ins.open("chartIn.txt" );
outs.open("chartOut.txt" );
while (!ins.eof())
{
ins >> rowNumber;
ins >> seat1 >> seat2 >> seat3 >> seat4;
chart[rowNumber - 1][0] = seat1;
chart[rowNumber - 1][1] = seat2;
chart[rowNumber - 1][2] = seat3;
chart[rowNumber - 1][3] = seat4;
outs << seat1 << seat2 << seat3 << seat4;
chart[rowNumber - 1][0] = seat1;
chart[rowNumber - 1][1] = seat2;
chart[rowNumber - 1][2] = seat3;
chart[rowNumber - 1][3] = seat4;
}
ins.close();
outs.close();
}
Last edited on Apr 12, 2015 at 10:45pm UTC
Apr 13, 2015 at 3:12am UTC
You are not writing the row number
Topic archived. No new replies allowed.