Friday, 16 September 2011

SYMBOL TABLE HASHING LAB PROGRAM

 
 
PROGRAM:
#include<stdio.h>
#include<string.h>
struct inter
{
int add;
char label[10];
char opcode[10];
char operand[10];
}st;
main()
{
int a[10]={0,0,0,0,0,0,0,0,0,0};
int n,hashval,val;
FILE *fp1,*fp2;
fp1=fopen("inters.txt","r");
fp2=fopen("symbols.txt","w");
printf("enter the value of n");
scanf("%d",&n);
while(!feof(fp1))
{
l1:fscanf(fp1,"%d%s%s%s",&st.add,st.label,st.opcode,st.operand);
if((strcmp(st.label,"NULL"))!=0)
{
printf("enter the hash value:");
scanf("%d",&val);
hashval=val%10;
if(a[hashval]==0)
{
a[hashval]=val;
fprintf(fp2,"%d\t%d\t%s\t%d\n",val,hashval,st.label,st.add);
}
else
{
for(hashval++;hashval<n;hashval++)
{
if(a[hashval]==0)
{
printf("space is allocated give some other value");
a[hashval]=val;
fprintf(fp2,"%d\t%d\t%s\t%d\n",val,hashval,st.label,st.add);
}
goto l1;
}
}
}
}
fcloseall();
}

0 comments:

Post a comment