Hi check my program i have used to read a FILE( nice.ls is shown below the program). I am able to read the FILE nice.ls, but i also have to check whether it starts with interger and next i have to check the hexadecimal if no hexadecimal then it should check for character.
I am able to read the hexadecimal but not able to read if hexadecimal is not present, PLZ help me..
# include <stdio.h>
#include<conio.h>
#define TRUE 1
int main()
{
FILE * pFile;
char stg [1024];
int i=0;
char line[1024];
char *ch;
char *p;
unsigned long int addr,opcode;
int j,k,l,m;
char n;
char inst1[10],inst2[10];
pFile = fopen ("nice.ls" , "r");
if (pFile == NULL) perror ("Error opening file");
else {
while(ch =fgets (stg , 1024 , pFile)) {
if(ch =='\n') {
line[i] = '\0';
return i;
}
else line[i] = ch;
i++;
if( fscanf(pFile, "%d",&j)== TRUE){
//printf("%d\n",j);
if(fscanf(pFile,"%s",&inst1) == TRUE ) {
printf(" %d %s \n",j,inst1);
}}//else if (fscanf(pFile,"%
/* else if(fscanf(pFile,"%x",&k) == TRUE) {
if(fscanf(pFile,"%x",&l) == TRUE)
printf("%d %x %x\n",j, k,l);
// if(fscanf(pFile,"%x",&l)==TRUE ) {
// if(fscanf(pFile,"%s",&inst1) == TRUE) {
// if(fscanf(pFile,"%s",&inst2) == TRUE)
// printf("%d %x %x %s %s \n",j,k,l,inst1,inst2);
}} */
else printf("error");
// fscanf( pFile, "%x",&k);
// fscanf( pFile, "%x", &l);
// fscanf( pFile, "%s %s",&inst1,&inst2);
// printf("%d %x %x %s %s\n",j,k,l,inst1,inst2);
// sscanf(ch,"%d %lx %lx %s %s ",&j,&addr,&opcode, inst1,inst2);
// printf("%d %lx %lx %s %s\n",j,addr,opcode,inst1,inst2);
}
}
fclose (pFile);
getch();
}
MY nice.ls FILE
1 ; C Compiler for M68HC08 (COSMIC Software)
2 ; Generator V4.5.10.1 - 14 Jun 2007
3 ; Optimizer V4.5.4.2 - 17 Jul 2007
5 xref _printf
32 ; 1 void main(void)
32 ; 2 {
33 switch .text
34 0000 _main:
38 ; 3 printf(" hello world ");
40 0000 a600 lda #low(L71)
41 0002 ae00 ldx #high(L71)
43 ; 4 }
46 0004 cc0000 jmp _printf
58 xdef _main
59 .const: section .text
60 0000 L71:
61 0000 2068656c6c6f dc.b " hello world ",0
62 end