I am trying to remove comments from an assembly instructions file, then print clean instructions in another file.
For example: This
TESTD TD STDIN
JEQ TESTD . Loop until ready
RD STDIN . Get input to see how many times to loop
STA NUMLOOP . Save the user's input into NUMLOOP
STLOOP STX LOOPCNT . Save how many times we've loops so far
Becomes this:
TESTD TD STDIN
JEQ TESTD
RD STDIN
STA NUMLOOP
STLOOP STX LOOPCNT
==========================================================================
I wrote this program to remove any thing after the point that mark comments including the dot, but it did not work; output file have the same line containing the comments as the input file.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
FILE *fp, *fp2; // input and output file pointers
char ch[1000];
fp = fopen(argv[1], "r");
fp2 = fopen(argv[2],"w");
while( fgets(ch, sizeof(ch), fp)) // read line into ch array
{
int i = 0 ;
for( ch[i] ; ch[i]<=ch[1000] ; ch[i++]) // loop to check all characters in the line array
{
if(ch[i] == '.')
{
for( ch[i] ; ch[i] <= ch[1000] ; ch[i++])
{
ch[i] = '\0'; //making all characters after the point NULL
}
}
continue;
}
fputs(ch, fp2);
}
fclose(fp);
fclose(fp2);
return(0);
}