Hi,
I'm working on a project where I have a text file that needs to be parsed into assembler instructions. For example: 01364820,8D280000,FFFFFFFF will be parsed as:
ADD $t1, $t1, $s6
LW $t0, 0($t1)
I need help parsing the text file. I thought I would start by first reading the file, which I got the program to do. Then I wanted to write what I read into another file, say, output.txt. I figure once I can figure that out, then I'll work on converting the code to assembler instructions. Two things seem to be giving me problems...(1) how to handle the comma in the comma delimited file so that I have a seperate instruction on individual lines. (2) how to write to a file. Thanks for any help!
#include <stdio.h>
FILE *fp; /*fp is a pointer to a FILE */
main(){
char ch;
fp=fopen("txtfile.txt","r"); /* open the file for reading */
while (fp != NULL){
ch = fgetc(fp);
if (ch == EOF)
break;
else{
putchar(ch);
printf("%c",ch);
}//end else
}
fclose(fp); /* close the file */
}