Code stopped working while debugging..

I just came across code for offline debugging, but as i added it in a solution code my solution code stopped working.

Debugging code:

  #ifndef ONLINE_JUDGE
 freopen("a.in", "r" , stdin);
 freopen("a.out", "w", stdout);
 #endif

I implemented ifndef (debugging) for first time pelase guide me…!!

Code link: rnWwtR - Online C++ Compiler & Debugging Tool - Ideone.com

Code is of problem CAPPLE from December challenge but solution do not have bugs but i think so the way i am implementing debugging code is not correct.!! Still if one want to visit problem so problem link is:

CodeChef: Practical coding for everyone .

Please guide me to a proper way for using the offline debugging method…

Please help…!

This is because that the judge does not contains “a.in” file.So just change to these :

freopen(fi, “r” , stdin);

freopen(fo, “w”, stdout);

But in your PC, if “a.in” file is present then it’s perfectly fine to use your approach.In this case, the output is written to “a.out” file.Check out this : http://ideone.com/V3EpAH
Also look at this : Save time with -ONLINE_JUDGE - Codeforces

1 Like

but i am using a file named a.in which is stored in the same directory where the solution code is saved

Also i want to tell you if i paste debugging code in another program then it works… :frowning: but i am not getting why is it not working for this code…

I didn’t get you, can you please give the link for the code which works.

It works perfectly fine or me.I mean(“a.in”,“source code” are present in same directory, when I executed it output is written to “a.out”).

okay let me check it again, dont know why that didn’t worked…!! :frowning:

Bro i am feeling embarrassed…!!

Sorry i was putting a.in file in wrong directory…!! thanks…

But for general case will using fi and fo work? mean that i dont know the name of input/output file so i should use fi and fo…?

And really sorry for wasting your time… :frowning: