Reading/writing from a .txt file

Hi,

I am a beginner in C++. I use Dev C++. I wrote the following code:


Parameter_Manager a(80);
FILE *input;
char nameinput[128]="input_MIMO_LOS_baseline.txt";

input=fopen(nameinput,"r+");
if(input==0)
input=fopen(nameinput,"w+");
if(input==0)
exit(1);
a.Add_Parameter_From_File(input,"Es/N0 [dB]",&esn0db);
a.Add_Parameter_From_File(input,"Number of simulated blocks",&MAX_NUM_FRAME);
a.Add_Parameter_From_File(input,"Number of frame errors",&MAX_NUM_FERRORS);
a.Add_Parameter_From_File(input,"FER threshold",&FER_threshold);
a.Add_Parameter_From_File(input,"Information block length",&Kc);
a.Add_Parameter_From_File(input,"Router",&Router);
a.Add_Parameter_From_File(input,"Offset",&off);
a.Add_Parameter_From_File(input,"Modulation efficiency",&m);
a.Add_Parameter_From_File(input,"Number of transmit antennas",&Nt0);
a.Add_Parameter_From_File(input,"Number of receive antennas",&Nr0);
a.Add_Parameter_From_File(input,"Dual-polar channel?",&Dual);
a.Add_Parameter_From_File(input,"XPD [dB]",&XPDdB);
a.Add_Parameter_From_File(input,"Distance TX-RX [km]",&dist);
a.Add_Parameter_From_File(input,"Deviation factor [dB]",&etadB);
a.Add_Parameter_From_File(input,"Polar angle of transmit ULA [degrees]",&thetatD);
a.Add_Parameter_From_File(input,"Polar angle of receive ULA [degrees]",&thetarD);
a.Add_Parameter_From_File(input,"Azimut of receive ULA [degrees]",&phirD);
a.Add_Parameter_From_File(input,"Carrier frequency [GHz]",&fc);
a.Add_Parameter_From_File(input,"Channel coherence time",&T_coh);
a.Add_Parameter_From_File(input,"Rice factor [dB]",&KricedB);
a.Add_Parameter_From_File(input,"MIMO demodulation (1) or not (0)?",&flag_MIMO);
a.Add_Parameter_From_File(input,"ESE type",&Ese_type);
a.Add_Parameter_From_File(input,"Number of iterations SCCC decoder",&niter);
a.Add_Parameter_From_File(input,"Number of iterations receiver",&niter_st);
fclose(input);
if(a.error)
{
printf("Main: The file %s was not ready. Fill up all the required parameters.\n",nameinput);
//exit(1);
}

There is a library "Parameter_Manager.h" and there is an input file with the name input_MIMO_LOS_baseline.txt in the same folder. Unfortunately, on compiling and running, I see the msg "Main: The file %s was not ready. Fill up all the required parameters", which is not expected, since the input file has all the parameters. I am sure there is some problem in the fopen section, but I dont know what. Please help..
Topic archived. No new replies allowed.