Skip to content

Instantly share code, notes, and snippets.

@seekshiva
Created August 26, 2012 23:05
Show Gist options
  • Save seekshiva/3484168 to your computer and use it in GitHub Desktop.
Save seekshiva/3484168 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
int power (int m,int i)
{
int j,sum=1;
if(i==0)
return 1;
else if(i==1)
return m;
else
{
for(j=0;j<I;j++)
sum*=m;
}
return sum;
}
int decimal(char *a)
{
int i=0;sum=0;m,p;
p=strlen(a);
while(a[i]!=’\0’)
{
if(a[i]=48 && a[i]<=57)
m=a[i]-48;
if(a[i]>=65 && a[i]<=70)
m=a[i]-55;
sum+=(m*power(16,p-1));
p--;
i++;
}
return sum;
}
void main()
{
char a[300][3],str[100],lo[25],s[25],name1[25],name2[25],s1[25],len[25];
int I,j,l,q,z,c=0,flag,ato,loc,..strloc..,cnt,max,space;
FILE *f;
for(i=0;i<300;i++)
strcpy(a[i],”XX”);
f=fopen(“source.txt”,”r”);
fscanf(f,”%s”,str);
for(j=2;j<8;j++)
{
if(str[j] !=’ ‘)
name1[c++]=str[j];
}
name1[c]=’\0’;
c=0;
for(j=9;j<15;j++)
s1[c++]=str[j];
s1[c]=’\0’;
strloc=decimal(s1);
c=0;
for(j=16;j<22;j++)
len[c++]=str[j];
len[c]=’\0’;
max=decimal(len);
printf(“Enter the name of the program:”);
scanf(“%s”,name2);
printf(“Enter the available memory space:”);
scanf(“%d”,space);
if(!strcmp(name1,name2))
{
do
{
fscanf(f,”%s”,str);
if(str[0]==’E’)
goto a;
j=0;
flag=0;
z=1=0;
cnt=0;
do
{
if(!flag)
{
flag++;
j=2;
do
{
lo[l++]=str[j];
}while(str[++j]!=’^’);
lo[1]=’\0’;
loc=decimal(lo);
cnt=loc-strloc;
j=12; // j is set to 12 here
}
/*
z=0;
do
{
s[z++]=str[j];
}while(str[++j]!=’\0’); // like this
s[z]=’\0’;
j++;
*/
for(i=0;i<3;i++)
{
a[cnt][0]=str[j++];
a[cnt++][1]=str[j++];
}
}while(str[j]!=’\0’);
}while(!feof(f));
a:
printf(“\n%X\t”,strloc);
for(i=0,c=0;i<300;++c)
{
printf(“%s”,a[i]);
if(c==4)
{
printf(“ “);
c=0;
}
++i;
if(i%16==0)
{
strloc+=16;
printf(“\n%X\t”,strloc);
}
}
else
printf(“CANNOT LOAD THE GIVEN FILE”);
fclose(f);
}
Source:
-SOURCE.txt
H^SAMPLE^21^001000
T^001015^12^1C1012^0C1018^00101B^181012^0C101E
T^001032^03^454F46
E^001000
Output:
Enter the program name:SAMPLE
Enter the available memory:100
1000 XXXXXXXX XXXXXXXX XXXXXXXX
1010 XXXXXXXX XX1C1012 0C101800
1020 120C101E XXXXXXXX XXXXXXXX
1030 XXXX454F 46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment