buffer not writing to file
suddenly nothing is written to my file
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
void taglessLine(char line[],ofstream& buffer){
buffer.open("buffer.txt", ios::out);
int len=strlen(line);
char tagl[chr_len];
int i=0;
while(i<len){
if (line[i]=='<'){
tagl[i]='\0';
break;}
else{
tagl[i]=line[i];
i++;
}
}
if(buffer.is_open()){
cout<<"write Succes"<<endl;
buffer<<tagl<<endl;}
else
cout<<"error"<<endl;
buffer.close();
}/code]
[code]void readFile(char file[], fstream& read){
char line[chr_len];
char word;
ofstream buffer;
int i=0;
read.open(file);
char tagl[chr_len];
int len=0;
if(read.fail())
cout<<"Sorry could not read";
else{
read.ignore(200, '\n');
read.ignore(200, '\n');
read.ignore(200, '\n');
while (read.good()){
read>>word;
if(word=='<'){
while(word!='>'){
read>>word;
}}
read.getline(line,chr_len);
taglessLine(line, buffer);
}}
//buffer.close();
read.close();
}
|
fixed. it every time i was openeing the file it was erasing everything, so I opened it at start in readfile...:)
1 2 3 4 5 6 7 8 9 10 11 12
|
int i=0;
while(i<len){
if (line[i]=='<'){
tagl[i]='\0';
break;}
else{
tagl[i]=line[i];
i++;
}
}
|
I think a for loop would be clearer here. It lets the reader see the structure of the loop separate from what's happening at each iteration:
1 2 3 4 5 6 7 8
|
for (int i = 0; i < len; ++i) {
if (line[i]=='<'){
tagl[i]='\0';
break;
} else {
tagl[i]=line[i];
}
}
|
Topic archived. No new replies allowed.