Question: im running this code on terminal but it wont compile successfully ... whats the problem ? #include #include #include void cross_refer(); int main(int argc, char

im running this code on terminal but it wont compile successfully ... whats the problem ?

#include

#include

#include

void cross_refer();

int main(int argc, char **argv){

int i = 0;

FILE *fp ,*fp1;

fp = fopen(argv[2], "r"); /* open inputfile in read mode */

fp1 = fopen(argv[3], "w"); /* open outputfile in write mode */

/* error message for invalide command line arguments */

if(argc !=4){

printf("Usage: prog4.out flag inputfile outputfile ");

return 0;

}

char flag = argv[1][1];

char s[100];

/* check flag argument */

switch(flag){

/* write source program into outputfile with list of labels of the MAL source program used as variables */

case 'v': fclose(fp1);

cross_refer_data(argv[2], argv[3]);

break;

/* write source program into outputfile with list of labels of the MAL program used for the flow control */

case 'f': fclose(fp1);

cross_refer_text(argv[2], argv[3]);

break;

/* write source program into outputfile with (i) a list of labels of the MAL source program used as variables,

and (ii) a list of labels of the MAL program used for the flow control */

case 'b': close(fp1);

cross_refer(argv[2], argv[3]);

break;

default: printf("Invalid flag ");

break;

}

}

void cross_refer(char *in, char *out){

char line[64], iden[100][10];

int i, j=0, k, x=0, l=0;

FILE *fp2 ,*fp3;

fp2 = fopen(in, "r");

fp3 = fopen(out, "a");

fprintf(fp3," Cross reference Table ");

while((fgets(line, 64, fp2))!=NULL){

if(strchr(line, ':')){

for(i=0; line[i]; i++)

if(line[i]!=':')

iden[j][i] = line[i];

else{

iden[j][i] = '\0';

break;

}

j++;

}

if(strchr(line, ',')){

for(i=0; line[i]; i++)

if((line[i] ==',')&& (line[i+1]!='$') && (!isdigit(line[i+1])))

{

for(k=i+1; line[k]!=' '; k++)

iden[j][x++] = line[k];

iden[j][x++] = '\0';

break;

}

j++;

}

}

rewind(fp2);

for(i=0; i

fprintf(fp3, "%s ", iden[i]);

while((fgets(line, 64, fp2))!=NULL){

l++;

if(strstr(line, iden[i]))

fprintf(fp3, "%d ", l);

}

rewind(fp2);

l=0;

fprintf(fp3, " ");

}

printf("done ");

}

void cross_refer_data(char *in, char *out){

char line[64], iden[100][10];

int i, j=0, k, x=0, l=0;

FILE *fp2 ,*fp3;

fp2 = fopen(in, "r");

fp3 = fopen(out, "a");

fprintf(fp3," Cross reference Table ");

while((fgets(line, 64, fp2))!=NULL){

if(strchr(line, '.data')){

while((fgets(line, 64, fp2))!=NULL){

if(strchr(line, ':')){

for(i=0; line[i]; i++)

if(line[i]!=':')

iden[j][i] = line[i];

else{

iden[j][i] = '\0';

break;

}

j++;

}

if(strchr(line, ',')){

for(i=0; line[i]; i++)

if((line[i] ==',')&& (line[i+1]!='$') && (!isdigit(line[i+1])))

{

for(k=i+1; line[k]!=' '; k++)

iden[j][x++] = line[k];

iden[j][x++] = '\0';

break;

}

j++;

}

if(strchr(line, '.text')){

break;

}

}

}

}

rewind(fp2);

for(i=0; i

fprintf(fp3, "%s ", iden[i]);

while((fgets(line, 64, fp2))!=NULL){

l++;

if(strstr(line, iden[i]))

fprintf(fp3, "%d ", l);

}

rewind(fp2);

l=0;

fprintf(fp3, " ");

}

printf("done ");

}

void cross_refer_text(char *in, char *out){

char line[64], iden[100][10];

int i, j=0, k, x=0, l=0;

FILE *fp2 ,*fp3;

fp2 = fopen(in, "r");

fp3 = fopen(out, "a");

fprintf(fp3," Cross reference Table ");

while((fgets(line, 64, fp2))!=NULL){

if(strchr(line, '.text')){

while((fgets(line, 64, fp2))!=NULL){

if(strchr(line, ':')){

for(i=0; line[i]; i++)

if(line[i]!=':')

iden[j][i] = line[i];

else{

iden[j][i] = '\0';

break;

}

j++;

}

if(strchr(line, ',')){

for(i=0; line[i]; i++)

if((line[i] ==',')&& (line[i+1]!='$') && (!isdigit(line[i+1])))

{

for(k=i+1; line[k]!=' '; k++)

iden[j][x++] = line[k];

iden[j][x++] = '\0';

break;

}

j++;

}

if(strchr(line, '.data')){

break;

}

}

}

}

rewind(fp2);

for(i=0; i

fprintf(fp3, "%s ", iden[i]);

while((fgets(line, 64, fp2))!=NULL){

l++;

if(strstr(line, iden[i]))

fprintf(fp3, "%d ", l);

}

rewind(fp2);

l=0;

fprintf(fp3, " ");

}

printf("done ");

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!