i need help with the code below. it doesn't give out the right output. the output is supposed to appear in a symbol table form

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
struct instruction
{
char iden[10];
char name[10];
   }in;


void main()
{
FILE *fin,*fesym;
int v1,v2,val,*cslth,val1,val2,c,d;

char *id1,*id2,name2[10],v[10];
int csaddr=0,progaddr,temp1;

clrscr();

 fin=fopen("pass1.c","r");
 fesym=fopen("symtable.c","w");

  printf("\t\t\tCreation of external symbol table\n");
  printf("Enter the relocation address");
  scanf("%d",&progaddr);

  csaddr=progaddr;

    printf("Starting address:%d",progaddr);
    printf("\n First control section address: %d",csaddr);

     fprintf(fesym,"____External symbol table___");
     fscanf(fin,"%s%s",in.iden,in.name);

      while(!feof(fin))
    {
      if(strcmp(in.iden,"H")==0)
        {
          int t;

          fscanf(fin,"%s%s",id1,val);
          fprintf(fesym,"\nControl section name\tsymbolname\taddress\tlength");
          fprintf(fesym,"\n%s\t\t\t\t\t%d\t\t%s",in.name,csaddr,val);
        val=cslth;
        }


         else if(strcmp(in.iden,"H1")==0)
           {
             int t;

             fscanf(fin,"%s%s",id1,val1);
             fprintf(fesym,"\n%s\t\t\t\t\t%d\t\t%s",in.name,c,csaddr,val1);

             val1=cslth;
             t=atoi(cslth);
             csaddr=t+csaddr;

             printf("\nLast control section address:%d",csaddr);
            }

              else if(strcmp(in.iden,"H2")==0)
               {
                 int t;
                  fscanf(fin,"%s%s",id1,val2);
                  fprintf(fesym,"\n%s\t\t\t\t\t%d\t%s",in.name,c,csaddr,val2);

                val2=cslth;
                t=atoi(cslth);
                csaddr=t+csaddr;
            printf("%d",csaddr);
              }

              else if(strcmp(in.iden,"D")==0)
                {
                int n,m,temp,temp1;
                 fscanf(fin,"%s%s%s",id1,name2,id2);

                 n=atoi(id1);
                 m=atoi(id2);

                 temp=csaddr+n;
                 temp1=csaddr+m;

                 fprintf(fesym,"\n\t\t\t%s\t\t%d\n\t\t\t%s\t\t%d\n",in.name,temp,name2,temp1);
                 c=atoi(cslth);
                 csaddr=c+csaddr;

                  }
                   fscanf(fin,"%s%s",in.iden,in.name);
                      } fclose(fesym);
                getch();
}

why don't u just use fgets and read in portion coz like this your scanning starting addr of the file which u can't do that coz u didn't read the buffer of the file or anything into a string so u cant expect it to start directly i suggest you use fgets since u want to compare some string you can read the all buffer at once using fread

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.