c - debug assertion expression stream!=null every time i use fopen -
i'm having problems not 1 2 3 programs using files , commands fopen, fscanf, while(strcmp(input,"e")!=0).atleast, think problem. these programs show same error debug assertion failed! expression (stream!=null).i tried nothing seems work pls help. cant understand do. pls reply possible.this 1 of programs:
# include <stdio.h> # include <conio.h> # include <string.h> # include <stdlib.h> void main() { char add[6],length[10],input[10],binary[12],bitmask[12],relocbit; int start,inp,len,i,address,opcode,addr,actualadd; file *fp1=fopen("relinput.dat","r"); file *fp2=fopen("reloutput.dat","w"); system("cls"); printf("enter actual starting address : "); scanf("%d",&start); fscanf(fp1,"%s",input); while(strcmp(input,"e")!=0) { if(strcmp(input,"h")==0) { fscanf(fp1,"%s",add); fscanf(fp1,"%s",length); fscanf(fp1,"%s",input); } if(strcmp(input,"t")==0) { fscanf(fp1,"%d",&address); fscanf(fp1,"%s",bitmask); address+=start; len=strlen(bitmask); for(i=0;i<len;i++) { fscanf(fp1,"%d",&opcode); fscanf(fp1,"%d",&addr); relocbit=bitmask[i]; if(relocbit=='0') actualadd=addr; else actualadd=addr+start; fprintf(fp2,"%d\t%d%d\n",address,opcode,actualadd); address+=3; } fscanf(fp1,"%s",input); } } fclose(fp1); fclose(fp2); printf("finished"); getch(); }
you need error checking on fopen procedures , in general. error due fscanf or fopen returning unexpected value didn't catch.
more useful tips:
- debug breakpoints if ide allows to
- format code more in line , readable
- comment on functions make clear do, future readers or future self.
Comments
Post a Comment