开发者

Unique behavior of my program , Unable to identify

There is some problem during the run time of my program and i am unable to get what the problem is.

what happens basically is , my program automatically closes and displays the following in Microsoft visual c++ 2010 express window

Unique behavior of my program , Unable to identify

What could be the reasons for this ? I have no idea why this is happening.

Let me tell that in my program i have used pointers too often and have used character arrays which i write to the disc

The program is too large to display

This is the function called after which my program stops开发者_JS百科 :

void display_databases()
{


 struct info_of_trains
 {
int train_no;
char train_name[25];
char boarding_pt[25];
char destination[25];
int first_seats;
int fare_first;
int second_seats;
int fare_second;
char  date[20];
    };



    info_of_trains e;

  cout<<"TRno.  TRname     B.pt    D.pt    F.seats    F.fare   S.seats   F.second   Date\n";
  FILE *fp;
  fp=fopen("database","r");
  if(fp==NULL)
  {
cout<<"failure";
  }
  else
  {
  while(fread(&e,sizeof(e),1,fp)==1)
  {

printf(e.train_no,e.train_name,e.boarding_pt,e.destination,e.first_seats,e.fare_first,e.second_seats,e.fare_second,e.date);
  cout<<"-------------------------------------------------------------------------------\n";
   }
   fclose(fp);
   }
   }

This is where execution stops :!


You seem to have hit a breakpoint, or your program had an access violation (reading an illegal pointer). You also seem to have maximized/detached the debugging panels. You can reattach the panel by dragging the yellow bar at the top to the lower part of the screen.

Did you recieve a warning message before it happened? Otherwise, did you define a breakpoint (clicking in the left margin of the code editor, so a red circle appears there)

EDIT: As pointed out in the comments, the error occurs because you use printf the wrong way. Use cout instead, as you did above:

cout << e.train_no <<" " <<  e.train_name << " " << e.boarding_pt << " " << e.destination << " " << e.first_seats << " " << e.fare_first << " " << e.second_seats << " " << e.fare_second << " " << e.date << endl;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜