I need help on how to properly combine two programs into a single program.
This is the first program:
int main()
{
FILE *input, *output;
char doc;
input = fopen("input3.txt","r");
output = fopen("output.txt","w");
while(!feof(input))
{
doc=fgetc(input);
if(doc==EOF) break;
else
{
if(doc==';')
{
while(!feof(input))
{
doc=fgetc(input);
if(doc=='\n')
goto out;
}
}
}
out: fputc(doc, output);
}
fclose(input);
fclose(output);
return 0;
}
This removes comments
This is the second program:
int main ()
{
FILE *input, *output;
input = fopen("output3.txt","r");
output = fopen("output4.txt","w");
char cmd[5], op[20], temp;
int x;
while(!feof(input))
{
fscanf(input, "%s %s", &cmd, &op); //no, str, cmd, operand
temp = fgetc(input);
char *search=",";
char *op1=strtok(op, search);
char *op2=strtok(NULL,search);
char *op3=strtok(NULL,search);
if(op3!=NULL)
{
fprintf(output, "%s\n\n%s\n,\n%s\n,\n%s\n", cmd, op, op2, op3);
}
else if(op2!=NULL)
{
fprintf(output, "%s\n\n%s\n,\n%s\n", cmd, op, op2);
}
else fprintf(output, "%s\n\n%s\n", cmd, op);
}
fclose(input);
fclose(output);
return 0;
}
This breaks down the input
I tried it using this
int main()
{
FILE *src, *noc, *brk;
char doc;
char no[5], str[10], cmd[5], op[50];
int x;
src = fopen("lexer.asm","r");
noc = fopen("nocomment.noc","w+");
brk = fopen("breakdown.brk","w");
//Removes comments
while(!feof(src))
{
doc=fgetc(src);
if(doc==EOF) break;
else
{
if(doc==';')
{
while(!feof(src))
{
doc=fgetc(src);
if(doc=='\n')
goto out;
}
}
}
out: fputc(doc, nocw);
}
//Breakdown
while(!feof(noc))
{
fscanf(noc, "%s %s %s %s", &no, &str, &cmd, &op);
char *search=",";
char *op1=strtok(op, search);
char *op2=strtok(NULL,search);
char *op3=strtok(NULL,search);
if(op3!=NULL)
{
fprintf(brk, "%s\n\n%s\n,\n%s\n,\n%s\n", cmd, op, op2, op3);
}
else if(op2!=NULL)
{
fprintf(brk, "%s\n\n%s\n,\n%s\n", cmd, op, op2);
}
else fprintf(brk, "%s\n\n%s\n", cmd, op);
}
fclose(src);
fclose(noc);
fclose(brk);
return 0;
}
However using this solution, it only removes the comments, and doesn't do the second program.
My input in this program is:
1 byte MOV a,b ;comment
2 bytes SUB b,a ;comment
3 bytes HHH ga,me ;comment
Can anyone suggest anything to help me combine the two programs.