Reading file, simplify logic

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Here is code I wrote that reads the contents of a 387x387 table saved in a text file to a vector. Does anyone know how to make the code shorter, it is really long because there are 387 columns to read. Here is the code.

int Read_xFwdVolsFunds(void)<br/>
{ int x1;<br/>
char chrX[1000]; <br/>
int ret=0;<br/>
int i=1;<br/>
FILE * infile; <br/>
char temp_name[1000];<br/>
strcpy(temp_name, cRunLocation);<br/>
strcat(temp_name, "xFwdVols.csv");<br/>
infile = fopen(temp_name, "r");<br/>
if(infile == NULL)<br/>
{ LogFile<<"Error - unsuccessful open of file xFwdVols.csv"<<endl;<br/>
return 0; //Do not necessarily have to read file<br/>
}<br/>
else<br/>
LogFile<<"Successfully opened file xFwdVols.csv"<<endl;<br/>
<br/>
ret = fscanf(infile,"%s",chrX); //To skip past the header<br/>
for(i=0;i<=360;i++)<br/>
{ ret = fscanf(infile,"%d,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,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%lf,%lf",
<br/>
&x1,<br/>
&FwdMthVols[1],<br/>
&FwdMthVols[2],<br/>
&FwdMthVols[3],<br/>
&FwdMthVols[4],<br/>
&FwdMthVols[4],<br/>
&FwdMthVols[5],<br/>
&FwdMthVols[6],<br/>
&FwdMthVols[7],<br/>
&FwdMthVols[8],<br/>
&FwdMthVols[9],<br/>
&FwdMthVols[10],<br/>
&FwdMthVols[11],<br/>
&FwdMthVols[12],<br/>
&FwdMthVols[13],<br/>
&FwdMthVols[14],<br/>
&FwdMthVols[15],<br/>
&FwdMthVols[16],<br/>
&FwdMthVols[17],<br/>
&FwdMthVols[18],<br/>
&FwdMthVols[19],<br/>
&FwdMthVols[20],<br/>
&FwdMthVols[21],<br/>
&FwdMthVols[22],<br/>
&FwdMthVols[23],<br/>
&FwdMthVols[24],<br/>
&FwdMthVols[25],<br/>
&FwdMthVols[26],<br/>
&FwdMthVols[27],<br/>
&FwdMthVols[28],<br/>
&FwdMthVols[29],<br/>
&FwdMthVols[30],<br/>
&FwdMthVols[31],<br/>
&FwdMthVols[32],<br/>
&FwdMthVols[33],<br/>
&FwdMthVols[34],<br/>
&FwdMthVols[35],<br/>
&FwdMthVols[36],<br/>
&FwdMthVols[37],<br/>
&FwdMthVols[38],<br/>
&FwdMthVols[39],<br/>
&FwdMthVols[40],<br/>
&FwdMthVols[41],<br/>
&FwdMthVols[42],<br/>
&FwdMthVols[43],<br/>
&FwdMthVols[44],<br/>
&FwdMthVols[45],<br/>
&FwdMthVols[46],<br/>
&FwdMthVols[47],<br/>
&FwdMthVols[48],<br/>
&FwdMthVols[49],<br/>
&FwdMthVols[50],<br/>
&FwdMthVols[51],<br/>
&FwdMthVols[52],<br/>
&FwdMthVols[53],<br/>
&FwdMthVols[54],<br/>
&FwdMthVols[55],<br/>
&FwdMthVols[56],<br/>
&FwdMthVols[57],<br/>
&FwdMthVols[58],<br/>
&FwdMthVols[59],<br/>
&FwdMthVols[60],<br/>
&FwdMthVols[61],<br/>
&FwdMthVols[62],<br/>
&FwdMthVols[63],<br/>
&FwdMthVols[64],<br/>
&FwdMthVols[65],<br/>
&FwdMthVols[66],<br/>
&FwdMthVols[67],<br/>
&FwdMthVols[68],<br/>
&FwdMthVols[69],<br/>
&FwdMthVols[70],<br/>
&FwdMthVols[71],<br/>
&FwdMthVols[72],<br/>
&FwdMthVols[73],<br/>
&FwdMthVols[74],<br/>
&FwdMthVols[75],<br/>
&FwdMthVols[76],<br/>
&FwdMthVols[77],<br/>
&FwdMthVols[78],<br/>
&FwdMthVols[79],<br/>
&FwdMthVols[80],<br/>
&FwdMthVols[81],<br/>
&FwdMthVols[82],<br/>
&FwdMthVols[83],<br/>
&FwdMthVols[84],<br/>
&FwdMthVols[85],<br/>
&FwdMthVols[86],<br/>
&FwdMthVols[87],<br/>
&FwdMthVols[88],<br/>
&FwdMthVols[89],<br/>
&FwdMthVols[90],<br/>
&FwdMthVols[91],<br/>
&FwdMthVols[92],<br/>
&FwdMthVols[93],<br/>
&FwdMthVols[94],<br/>
&FwdMthVols[95],<br/>
&FwdMthVols[96],<br/>
&FwdMthVols[97],<br/>
&FwdMthVols[98],<br/>
&FwdMthVols[99],<br/>
&FwdMthVols[100],<br/>
&FwdMthVols[101],<br/>
&FwdMthVols[102],<br/>
&FwdMthVols[103],<br/>
&FwdMthVols[104],<br/>
&FwdMthVols[105],<br/>
&FwdMthVols[106],<br/>
&FwdMthVols[107],<br/>
&FwdMthVols[108],<br/>
&FwdMthVols[109],<br/>
&FwdMthVols[110],<br/>
&FwdMthVols[111],<br/>
&FwdMthVols[112],<br/>
&FwdMthVols[113],<br/>
&FwdMthVols[114],<br/>
&FwdMthVols[115],<br/>
&FwdMthVols[116],<br/>
&FwdMthVols[117],<br/>
&FwdMthVols[118],<br/>
&FwdMthVols[119],<br/>
&FwdMthVols[120],<br/>
&FwdMthVols[121],<br/>
&FwdMthVols[122],<br/>
&FwdMthVols[123],<br/>
&FwdMthVols[124],<br/>
&FwdMthVols[125],<br/>
&FwdMthVols[126],<br/>
&FwdMthVols[127],<br/>
&FwdMthVols[128],<br/>
&FwdMthVols[129],<br/>
&FwdMthVols[130],<br/>
&FwdMthVols[131],<br/>
&FwdMthVols[132],<br/>
&FwdMthVols[133],<br/>
&FwdMthVols[134],<br/>
&FwdMthVols[135],<br/>
&FwdMthVols[136],<br/>
&FwdMthVols[137],<br/>
&FwdMthVols[138],<br/>
&FwdMthVols[139],<br/>
&FwdMthVols[140],<br/>
&FwdMthVols[141],<br/>
&FwdMthVols[142],<br/>
&FwdMthVols[143],<br/>
&FwdMthVols[144],<br/>
&FwdMthVols[145],<br/>
&FwdMthVols[146],<br/>
&FwdMthVols[147],<br/>
&FwdMthVols[148],<br/>
&FwdMthVols[149],<br/>
&FwdMthVols[150],<br/>
&FwdMthVols[151],<br/>
&FwdMthVols[152],<br/>
&FwdMthVols[153],<br/>
&FwdMthVols[154],<br/>
&FwdMthVols[155],<br/>
&FwdMthVols[156],<br/>
&FwdMthVols[157],<br/>
&FwdMthVols[158],<br/>
&FwdMthVols[159],<br/>
&FwdMthVols[160],<br/>
&FwdMthVols[161],<br/>
&FwdMthVols[162],<br/>
&FwdMthVols[163],<br/>
&FwdMthVols[164],<br/>
&FwdMthVols[165],<br/>
&FwdMthVols[166],<br/>
&FwdMthVols[167],<br/>
&FwdMthVols[168],<br/>
&FwdMthVols[169],<br/>
&FwdMthVols[170],<br/>
&FwdMthVols[171],<br/>
&FwdMthVols[172],<br/>
&FwdMthVols[173],<br/>
&FwdMthVols[174],<br/>
&FwdMthVols[175],<br/>
&FwdMthVols[176],<br/>
&FwdMthVols[177],<br/>
&FwdMthVols[178],<br/>
&FwdMthVols[179],<br/>
&FwdMthVols[180],<br/>
&FwdMthVols[181],<br/>
&FwdMthVols[182],<br/>
&FwdMthVols[183],<br/>
&FwdMthVols[184],<br/>
&FwdMthVols[185],<br/>
&FwdMthVols[186],<br/>
&FwdMthVols[187],<br/>
&FwdMthVols[188],<br/>
&FwdMthVols[189],<br/>
&FwdMthVols[190],<br/>
&FwdMthVols[191],<br/>
&FwdMthVols[192],<br/>
&FwdMthVols[193],<br/>
&FwdMthVols[194],<br/>
&FwdMthVols[195],<br/>
&FwdMthVols[196],<br/>
&FwdMthVols[197],<br/>
&FwdMthVols[198],<br/>
&FwdMthVols[199],<br/>
&FwdMthVols[200],<br/>
&FwdMthVols[201],<br/>
&FwdMthVols[202],<br/>
&FwdMthVols[203],<br/>
&FwdMthVols[204],<br/>
&FwdMthVols[205],<br/>
&FwdMthVols[206],<br/>
&FwdMthVols[207],<br/>
&FwdMthVols[208],<br/>
&FwdMthVols[209],<br/>
&FwdMthVols[210],<br/>
&FwdMthVols[211],<br/>
&FwdMthVols[212],<br/>
&FwdMthVols[213],<br/>
&FwdMthVols[214],<br/>
&FwdMthVols[215],<br/>
&FwdMthVols[216],<br/>
&FwdMthVols[217],<br/>
&FwdMthVols[218],<br/>
&FwdMthVols[219],<br/>
&FwdMthVols[220],<br/>
&FwdMthVols[221],<br/>
&FwdMthVols[222],<br/>
&FwdMthVols[223],<br/>
&FwdMthVols[224],<br/>
&FwdMthVols[225],<br/>
&FwdMthVols[226],<br/>
&FwdMthVols[227],<br/>
&FwdMthVols[228],<br/>
&FwdMthVols[229],<br/>
&FwdMthVols[230],<br/>
&FwdMthVols[231],<br/>
&FwdMthVols[232],<br/>
&FwdMthVols[233],<br/>
&FwdMthVols[234],<br/>
&FwdMthVols[235],<br/>
&FwdMthVols[236],<br/>
&FwdMthVols[237],<br/>
&FwdMthVols[238],<br/>
&FwdMthVols[239],<br/>
&FwdMthVols[240],<br/>
&FwdMthVols[241],<br/>
&FwdMthVols[242],<br/>
&FwdMthVols[243],<br/>
&FwdMthVols[244],<br/>
&FwdMthVols[245],<br/>
&FwdMthVols[246],<br/>
&FwdMthVols[247],<br/>
&FwdMthVols[248],<br/>
&FwdMthVols[249],<br/>
&FwdMthVols[250],<br/>
&FwdMthVols[251],<br/>
&FwdMthVols[252],<br/>
&FwdMthVols[253],<br/>
&FwdMthVols[254],<br/>
&FwdMthVols[255],<br/>
&FwdMthVols[256],<br/>
&FwdMthVols[257],<br/>
&FwdMthVols[258],<br/>
&FwdMthVols[259],<br/>
&FwdMthVols[260],<br/>
&FwdMthVols[261],<br/>
&FwdMthVols[262],<br/>
&FwdMthVols[263],<br/>
&FwdMthVols[264],<br/>
&FwdMthVols[265],<br/>
&FwdMthVols[266],<br/>
&FwdMthVols[267],<br/>
&FwdMthVols[268],<br/>
&FwdMthVols[269],<br/>
&FwdMthVols[270],<br/>
&FwdMthVols[271],<br/>
&FwdMthVols[272],<br/>
&FwdMthVols[273],<br/>
&FwdMthVols[274],<br/>
&FwdMthVols[275],<br/>
&FwdMthVols[276],<br/>
&FwdMthVols[277],<br/>
&FwdMthVols[278],<br/>
&FwdMthVols[279],<br/>
&FwdMthVols[280],<br/>
&FwdMthVols[281],<br/>
&FwdMthVols[282],<br/>
&FwdMthVols[283],<br/>
&FwdMthVols[284],<br/>
&FwdMthVols[285],<br/>
&FwdMthVols[286],<br/>
&FwdMthVols[287],<br/>
&FwdMthVols[288],<br/>
&FwdMthVols[289],<br/>
&FwdMthVols[290],<br/>
&FwdMthVols[291],<br/>
&FwdMthVols[292],<br/>
&FwdMthVols[293],<br/>
&FwdMthVols[294],<br/>
&FwdMthVols[295],<br/>
&FwdMthVols[296],<br/>
&FwdMthVols[297],<br/>
&FwdMthVols[298],<br/>
&FwdMthVols[299],<br/>
&FwdMthVols[300],<br/>
&FwdMthVols[301],<br/>
&FwdMthVols[302],<br/>
&FwdMthVols[303],<br/>
&FwdMthVols[304],<br/>
&FwdMthVols[305],<br/>
&FwdMthVols[306],<br/>
&FwdMthVols[307],<br/>
&FwdMthVols[308],<br/>
&FwdMthVols[309],<br/>
&FwdMthVols[310],<br/>
&FwdMthVols[311],<br/>
&FwdMthVols[312],<br/>
&FwdMthVols[313],<br/>
&FwdMthVols[314],<br/>
&FwdMthVols[315],<br/>
&FwdMthVols[316],<br/>
&FwdMthVols[317],<br/>
&FwdMthVols[318],<br/>
&FwdMthVols[319],<br/>
&FwdMthVols[320],<br/>
&FwdMthVols[321],<br/>
&FwdMthVols[322],<br/>
&FwdMthVols[323],<br/>
&FwdMthVols[324],<br/>
&FwdMthVols[325],<br/>
&FwdMthVols[326],<br/>
&FwdMthVols[327],<br/>
&FwdMthVols[328],<br/>
&FwdMthVols[329],<br/>
&FwdMthVols[330],<br/>
&FwdMthVols[331],<br/>
&FwdMthVols[332],<br/>
&FwdMthVols[333],<br/>
&FwdMthVols[334],<br/>
&FwdMthVols[335],<br/>
&FwdMthVols[336],<br/>
&FwdMthVols[337],<br/>
&FwdMthVols[338],<br/>
&FwdMthVols[339],<br/>
&FwdMthVols[340],<br/>
&FwdMthVols[341],<br/>
&FwdMthVols[342],<br/>
&FwdMthVols[343],<br/>
&FwdMthVols[344],<br/>
&FwdMthVols[345],<br/>
&FwdMthVols[346],<br/>
&FwdMthVols[347],<br/>
&FwdMthVols[348],<br/>
&FwdMthVols[349],<br/>
&FwdMthVols[350],<br/>
&FwdMthVols[351],<br/>
&FwdMthVols[352],<br/>
&FwdMthVols[353],<br/>
&FwdMthVols[354],<br/>
&FwdMthVols[355],<br/>
&FwdMthVols[356],<br/>
&FwdMthVols[357],<br/>
&FwdMthVols[358],<br/>
&FwdMthVols[359],<br/>
&FwdMthVols[360],<br/>
&FwdMthVols[361],<br/>
&FwdMthVols[362],<br/>
&FwdMthVols[363],<br/>
&FwdMthVols[364],<br/>
&FwdMthVols[365],<br/>
&FwdMthVols[366],<br/>
&FwdMthVols[367],<br/>
&FwdMthVols[368],<br/>
&FwdMthVols[369],<br/>
&FwdMthVols[370],<br/>
&FwdMthVols[371],<br/>
&FwdMthVols[372],<br/>
&FwdMthVols[373],<br/>
&FwdMthVols[374],<br/>
&FwdMthVols[375],<br/>
&FwdMthVols[376],<br/>
&FwdMthVols[377],<br/>
&FwdMthVols[378],<br/>
&FwdMthVols[379],<br/>
&FwdMthVols[380],<br/>
&FwdMthVols[381],<br/>
&FwdMthVols[382],<br/>
&FwdMthVols[383],<br/>
&FwdMthVols[384],<br/>
&FwdMthVols[385],<br/>
&FwdMthVols[386],<br/>
&FwdMthVols[387],<br/>
&FwdMthVols[388],<br/>
&FwdMthVols[389],<br/>
&FwdMthVols[390],<br/>
&FwdMthVols[391],<br/>
&FwdMthVols[392],<br/>
&FwdMthVols[393],<br/>
&FwdMthVols[394],<br/>
&FwdMthVols[395],<br/>
&FwdMthVols[396],<br/>
&FwdMthVols[397]);<br/>
if(ret == EOF) break;<br/>
}<br/>
fclose(infile);<br/>
return 0;<br/>
}

View the full article
 
Back
Top