-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquad.h
More file actions
62 lines (51 loc) · 1.02 KB
/
quad.h
File metadata and controls
62 lines (51 loc) · 1.02 KB
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
#define MAX 50
extern int iIndex;
struct quad
{
int no;
char _operator[10];
char op1[10];
char op2[10];
char result[10];
}Q[MAX];
void insert_instr(char *Operator,char *Op1,char *Op2,char *Result)
{
Q[iIndex].no = iIndex;
strcpy(Q[iIndex]._operator,Operator);
strcpy(Q[iIndex].op1,Op1);
strcpy(Q[iIndex].op2,Op2);
strcpy(Q[iIndex].result,Result);
iIndex++;
}
void insert_goto(int position,int goto_loc)
{
char temp[10],t[5];
strcpy(temp,"GOTO-");
sprintf(t,"%d",goto_loc);
strcat(temp,t);
strcpy(Q[position].result,temp);
}
void displayQuad()
{
int i;
printf("\n\nADDR\t OPERATOR\tOP1\t OP2\t\tRESULT\n");
for(i=1;i<iIndex;i++)
printf("\n%04d %10s %10s %10s %15s",Q[i].no,Q[i]._operator,Q[i].op1,Q[i].op2,Q[i].result);
printf("\n\n");
}
void writeQuad()
{
int i;
FILE *fp;
fp = fopen("quad","w");
if(fp==NULL)
{
printf("\nFile not created !\n");
return -1;
}
for(i=1;i<iIndex;i++)
{
fprintf(fp,"\n%04d %10s %10s %10s %15s",Q[i].no,Q[i]._operator,Q[i].op1,Q[i].op2,Q[i].result);
}
}
#undef MAX