hello everyone,
I am trying to read the same file twice,but after the first reading it is not taking the value again.
what i need to do is read the file once and count the number of lines in the file, then read it again and do further computations......
but my code is reading it once finding the number of lines and then it is not able to read it again.
ifstream input;
input.open("c:/prog.txt",ios::in); // opens the file;
ofstream output;
ofstream control;
ofstream registers;
registers.open("registerfile.txt");
control.open("controlfile.txt");
output.open("opfile.txt");
char txt[40],txt1[5];
if(!input) { // file couldn't be opened
cerr << "Error: file could not be opened" << endl;
}
if( !output ) { // file couldn't be opened
cerr << "Error: file could not be opened" << endl;
}
if( !control ) { // file couldn't be opened
cerr << "Error: file could not be opened" << endl;
}
string lines;
while(!input.eof())
{
getline(input,lines);
counter++;
}
input.seekg (0, ios::beg);
int w;
while(input>>txt1)
{
if (!strcmp("add",txt1))
{
cout<<"the opcode is add"<<endl;
not_imm(txt1,input,output,control,registers);
}
if(!strcmp("sub",txt1))
{
cout<<"the opcode is sub"<<endl;
not_imm(txt1,input,output,control,registers);
}
if(!strcmp("addi",txt1))
{
cout<<"the opcode is addi"<<endl;
imm(txt1,input,output,control,registers);
}
if(!strcmp("beq",txt1))
{
cout<<"the opcode is beq"<<endl;
imm(txt1,input,output,control,registers);
}
if(!strcmp("bne",txt1))
{
cout<<"the opcode is bne"<<endl;
imm(txt1,input,output,control,registers);
}
}
return 0;
output.close();
input.close();
control.close();
registers.close();