I'm making an SIC 2 pass assembler in C++. And I'm not very good at files in C++. The following code segment is supposed to read LABEL OPCODE OPERAND from the input text file . All it has to do is to identify each of those based on the tab which separates them.The problem here is that it fails to read the operand and also , it is read the first line again in a disordered manner. Please help
#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
int main()
{
char temp[10],tlabel[10],topcode[6],toperand[12];
ifstream fin("inputfile.txt",ios::in);
int a=0,b=0,i=0;
while(fin)
{
i=0;
a=0;
b=0;
fin.getline(temp,26);
while((temp[i]!='\0')&&(temp[i]!='\t'))
{
tlabel[i]=temp[i];
i++;
}
tlabel[i]='\0';
i++;
a=i;
while((temp[i]!='\0')&&(temp[i]!='\t'))
{
topcode[i-a]=temp[i];
i++;
}
topcode[i-a]='\0';
i++;
b=i;
while((temp[i]!='\0'))
{
toperand[i-b]=temp[i];
i++;
}
toperand[i-b]='\0';
cout<<tlabel<<"\t"<<topcode<<"\t";
cout<<"\n";
}
return 0;
}