Hi, I nee to write program that will arange my text files.
Every row in file is supposed to begin with '{'. If it is not the case then
I need the row that begin with every other character to place in current line
not write as new row. So in my result file every line should start with '{'.
I think I manage to do this and test it on one file and it seems to work fine.
I have three question:
1. Is there a better nad more elgant way to handle this
2. Do I have to close files.
3. (Not connected with upper two) When I want to write something in binary file
I open with something like this: ofstream ofs("name",ios_bas:binary);
and want to write I use something like this:
ofs.write((char*)&matrix[i][j],sizeof(double));
My question is way is ti necessary to erite (char *) and what it means?
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
char current[BUFSIZ];
char next[BUFSIZ];
int i=0;
ifstream in("Bow.sub");
ofstream out("BowlingPr.sub");
while(in.getline(current,BUFSIZ,'\n'))
{
i++;
in.getline(next,BUFSIZ,'\n');
if(current[0]=='{')
{
if(i!=1)
out<<'\n';
out<<current;
}
else
{
out<<current;
}
if(next[0]=='{')
{
out<<'\n';
}
out<<next;
}
}