#include <fstream>
#include <iomanip>
int main(int argc, char *argv[])
{
char X[14][5];
int i, j;
for (int i = 0; i < 14; i++)
for (int j = 0; j < 5; j++)
cin >> X[i][j];
ofstream out("file.txt"); // file.txt can be any name that your file might have
for (int i = 0; i < 14; i++)
{
for (int j = 0; j < 5; j++)
out << setw(5) << X[i][j]; // setw(n) -- n means that your string will have a field of 'n' spaces reserved
out << "\n";
}
return 0;
}
Here's another option: I like to save 2d arrays as a CSV (comma seperated value) file. It allows spreadsheet applications like Excel to open the file easily.
1 2 3 4 5 6 7 8 9 10 11 12
char* X[14][5];
// Populate X[][] here... Then do the following to write it to a csv file
ofstream out("file.csv");
for (int i = 0; i < 14; ++i)
{
for (int j = 0; j < 5; ++j)
out << X[i][j] << ',';
out << endl;
}
Question: Do you want to delete the 2D array, and never use it again ?
What confuses me, is the fact that I really don't know why do you need to delete it. If you need to use the 2D array again after printing it to file that is easy. If you want to delete is permanently and never use it again, then the delete is not needed as the function main has its own destructors which are being called at the end of the function.
If you want me to help you, please be more specific and tell me what exactly is your program about/what is it supposed to do/why do you find it necessary to delete the array/anything else that you can tell me so that I can understand what you are looking for.
Yes, I want to use this 2d array after deleting...
This is from my code...
User write something to that array and if user delete array then i want to go back to original state...
From linked list i move values to 2d array. And if user want to delete array then i need this code to delete it. I have deleted linked list but values stay in 2d array...When user delete it i want to go back to previus stage...On screen would be only days and hours
I really don't know why it crashes. :(
I'm sorry but I can't help you more with this because I didn't work with strings/characters before ( only for fun -- simple exercises ).
I hope someone can help you fix it and everything will run correctly as soon as possible.