i having problem saving a txt file and printing it back out , i have the hints of using fgets(v[i],14,infile); and sscanf(v[i],"%d: %s %s,%x"%line_num[i],inst[i],reg[2],reg2[0]); i have no idea on how to imply this correctly can someone show me a correct implemtation of the code so i can move forward to write the instructions for performing the asm language
text file is as follow:
1: MOV A, 00
2: ADD A, 01
3: CMP A, FF
4: JZ 6
5: JMP 2
6: OUT A
7: NOP
can someone show me the correct code for scanning and printing it out please
`Inline Code Example Here
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define boolean_t int
#define TRUE 1
#define FALSE 0
FILE *infile;
main()
{
char text[10];
char a[100];
char *data="data.txt";
char *test="test.txt";
int integer;
int textcheck,selection1,selection2,repeat;
while(textcheck==FALSE)
{
printf("enter string:");
scanf("%s",&text);
if(strcmp(text,data)==0)
{
textcheck=TRUE;
selection1=TRUE;
}
else if(strcmp(text,test)==0)
{
textcheck=TRUE;
selection2=TRUE;
}
else
{
printf("reenter text file name\n");
textcheck=FALSE;
}
}//testcheck while
if(selection1==TRUE)
{
infile = fopen("data.txt", "r");
if(infile == NULL)
{
printf("file missing!");
}
else
{
while(!feof(infile))
{
for(integer=0;integer<5;integer++)
{
fscanf(infile, "%c", &a[integer]);
}
for(integer=0;integer<5;integer++)
{
printf( "%c", a[integer]);
}
}
}
}//selection 1
if(selection2==TRUE)
{
infile = fopen("test.txt", "r");
if(infile == NULL)
{
printf("file missing!");
}
else
{
while(!feof(infile))
{
fscanf(infile, "%c\n", &a);
}
}
}//selection 2
system("pause");
}
`