error: lvalue required as left operand of assignment

This is a discussion on error: lvalue required as left operand of assignment within the C Programming forums, part of the General Programming Boards category; Code: typedef struct { name_t name; float beta[beta_num]; }gene_t; gene_t gene[300] /*assigning data to gene*/ /*some of them are allocated ...

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    11

    error: lvalue required as left operand of assignment

    Code:
    typedef struct {	name_t name;
    	float beta[beta_num];
    }gene_t;
    
    gene_t gene[300]
    
    /*assigning data to gene*/
    /*some of them are allocated dynamically*/
    
    for (i=0;i<count;i++) {
    	free(&gene[i]);
    	&gene[i]=NULL;
    }
    In the line '&gene[i]=NULL;' there is an error of 'lvalue required as left operand of assignment'.


    Do you know why @@ ? Thanks

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,554
    > /*some of them are allocated dynamically*/
    None of what you posted is dynamically allocated.
    So whilst your free() call is syntactically valid, it's totally meaningless at runtime, and would crash.

    Perhaps post what you're actually doing, or something a lot closer to what you're actually doing.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    11
    Here is my code of allocation

    Code:
    gene_t gene1;	
    	while(fscanf(fp,"%s %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f",
    		gene1.name, &gene1.beta[0], &gene1.beta[1], &gene1.beta[2], &gene1.beta[3], &gene1.beta[4], &gene1.beta[5], &gene1.beta[6], &gene1.beta[7], &gene1.beta[8], &gene1.beta[9], &gene1.beta[10], &gene1.beta[11], &gene1.beta[12], &gene1.beta[13], &gene1.beta[14], &gene1.beta[15], &gene1.beta[16], &gene1.beta[17], &gene1.beta[18], &gene1.beta[19], &gene1.beta[20], &gene1.beta[21], &gene1.beta[22], &gene1.beta[23], &gene1.beta[24], &gene1.beta[25], &gene1.beta[26], &gene1.beta[27], &gene1.beta[28], &gene1.beta[29], &gene1.beta[30], &gene1.beta[31], &gene1.beta[32], &gene1.beta[33], &gene1.beta[34], &gene1.beta[35], &gene1.beta[36], &gene1.beta[37], &gene1.beta[38], &gene1.beta[39], &gene1.beta[40], &gene1.beta[41], &gene1.beta[42], &gene1.beta[43], &gene1.beta[44], &gene1.beta[45], &gene1.beta[46], &gene1.beta[47], &gene1.beta[48], &gene1.beta[49], &gene1.beta[50], &gene1.beta[51], &gene1.beta[52], &gene1.beta[53], &gene1.beta[54], &gene1.beta[55], &gene1.beta[56], &gene1.beta[57], &gene1.beta[58], &gene1.beta[59], &gene1.beta[60], &gene1.beta[61], &gene1.beta[62], &gene1.beta[63], &gene1.beta[64], &gene1.beta[65], &gene1.beta[66], &gene1.beta[67], &gene1.beta[68], &gene1.beta[69], &gene1.beta[70], &gene1.beta[71], &gene1.beta[72], &gene1.beta[73], &gene1.beta[74], &gene1.beta[75], &gene1.beta[76], &gene1.beta[77], &gene1.beta[78], &gene1.beta[79], &gene1.beta[80], &gene1.beta[81], &gene1.beta[82], &gene1.beta[83], &gene1.beta[84], &gene1.beta[85], &gene1.beta[86], &gene1.beta[87], &gene1.beta[88], &gene1.beta[89], &gene1.beta[90], &gene1.beta[91], &gene1.beta[92], &gene1.beta[93], &gene1.beta[94], &gene1.beta[95], &gene1.beta[96], &gene1.beta[97], &gene1.beta[98], &gene1.beta[99], &gene1.beta[100], &gene1.beta[101], &gene1.beta[102], &gene1.beta[103], &gene1.beta[104], &gene1.beta[105], &gene1.beta[106], &gene1.beta[107], &gene1.beta[108], &gene1.beta[109], &gene1.beta[110], &gene1.beta[111], &gene1.beta[112], &gene1.beta[113], &gene1.beta[114], &gene1.beta[115], &gene1.beta[116], &gene1.beta[117], &gene1.beta[118], &gene1.beta[119], &gene1.beta[120], &gene1.beta[121], &gene1.beta[122], &gene1.beta[123], &gene1.beta[124], &gene1.beta[125], &gene1.beta[126], &gene1.beta[127], &gene1.beta[128], &gene1.beta[129], &gene1.beta[130], &gene1.beta[131], &gene1.beta[132], &gene1.beta[133], &gene1.beta[134], &gene1.beta[135], &gene1.beta[136], &gene1.beta[137], &gene1.beta[138], &gene1.beta[139], &gene1.beta[140], &gene1.beta[141], &gene1.beta[142], &gene1.beta[143], &gene1.beta[144], &gene1.beta[145], &gene1.beta[146], &gene1.beta[147], &gene1.beta[148], &gene1.beta[149], &gene1.beta[150], &gene1.beta[151], &gene1.beta[152], &gene1.beta[153], &gene1.beta[154], &gene1.beta[155], &gene1.beta[156], &gene1.beta[157], &gene1.beta[158], &gene1.beta[159], &gene1.beta[160], &gene1.beta[161], &gene1.beta[162], &gene1.beta[163], &gene1.beta[164], &gene1.beta[165], &gene1.beta[166], &gene1.beta[167], &gene1.beta[168], &gene1.beta[169], &gene1.beta[170], &gene1.beta[171], &gene1.beta[172], &gene1.beta[173], &gene1.beta[174], &gene1.beta[175], &gene1.beta[176], &gene1.beta[177], &gene1.beta[178], &gene1.beta[179], &gene1.beta[180], &gene1.beta[181], &gene1.beta[182], &gene1.beta[183], &gene1.beta[184], &gene1.beta[185], &gene1.beta[186], &gene1.beta[187], &gene1.beta[188], &gene1.beta[189], &gene1.beta[190], &gene1.beta[191], &gene1.beta[192], &gene1.beta[193], &gene1.beta[194], &gene1.beta[195], &gene1.beta[196], &gene1.beta[197], &gene1.beta[198], &gene1.beta[199], &gene1.beta[200], &gene1.beta[201], &gene1.beta[202], &gene1.beta[203], &gene1.beta[204], &gene1.beta[205], &gene1.beta[206], &gene1.beta[207], &gene1.beta[208], &gene1.beta[209], &gene1.beta[210], &gene1.beta[211], &gene1.beta[212], &gene1.beta[213], &gene1.beta[214], &gene1.beta[215], &gene1.beta[216], &gene1.beta[217], &gene1.beta[218], &gene1.beta[219], &gene1.beta[220], &gene1.beta[221], &gene1.beta[222], &gene1.beta[223], &gene1.beta[224], &gene1.beta[225], &gene1.beta[226], &gene1.beta[227], &gene1.beta[228], &gene1.beta[229], &gene1.beta[230], &gene1.beta[231], &gene1.beta[232], &gene1.beta[233], &gene1.beta[234], &gene1.beta[235], &gene1.beta[236], &gene1.beta[237], &gene1.beta[238], &gene1.beta[239], &gene1.beta[240], &gene1.beta[241], &gene1.beta[242], &gene1.beta[243], &gene1.beta[244], &gene1.beta[245], &gene1.beta[246], &gene1.beta[247], &gene1.beta[248], &gene1.beta[249], &gene1.beta[250], &gene1.beta[251], &gene1.beta[252], &gene1.beta[253], &gene1.beta[254], &gene1.beta[255], &gene1.beta[256], &gene1.beta[257], &gene1.beta[258], &gene1.beta[259], &gene1.beta[260], &gene1.beta[261], &gene1.beta[262], &gene1.beta[263], &gene1.beta[264], &gene1.beta[265], &gene1.beta[266], &gene1.beta[267], &gene1.beta[268], &gene1.beta[269], &gene1.beta[270], &gene1.beta[271], &gene1.beta[272], &gene1.beta[273], &gene1.beta[274], &gene1.beta[275], &gene1.beta[276], &gene1.beta[277], &gene1.beta[278], &gene1.beta[279], &gene1.beta[280], &gene1.beta[281], &gene1.beta[282], &gene1.beta[283], &gene1.beta[284], &gene1.beta[285], &gene1.beta[286], &gene1.beta[287], &gene1.beta[288], &gene1.beta[289], &gene1.beta[290], &gene1.beta[291], &gene1.beta[292], &gene1.beta[293], &gene1.beta[294], &gene1.beta[295], &gene1.beta[296], &gene1.beta[297], &gene1.beta[298], &gene1.beta[299], &gene1.beta[300], &gene1.beta[301], &gene1.beta[302], &gene1.beta[303], &gene1.beta[304], &gene1.beta[305], &gene1.beta[306], &gene1.beta[307], &gene1.beta[308], &gene1.beta[309], &gene1.beta[310], &gene1.beta[311], &gene1.beta[312], &gene1.beta[313], &gene1.beta[314], &gene1.beta[315], &gene1.beta[316], &gene1.beta[317], &gene1.beta[318], &gene1.beta[319], &gene1.beta[320], &gene1.beta[321], &gene1.beta[322], &gene1.beta[323], &gene1.beta[324], &gene1.beta[325], &gene1.beta[326], &gene1.beta[327], &gene1.beta[328], &gene1.beta[329], &gene1.beta[330], &gene1.beta[331], &gene1.beta[332], &gene1.beta[333], &gene1.beta[334], &gene1.beta[335], &gene1.beta[336], &gene1.beta[337], &gene1.beta[338], &gene1.beta[339], &gene1.beta[340], &gene1.beta[341], &gene1.beta[342], &gene1.beta[343], &gene1.beta[344], &gene1.beta[345], &gene1.beta[346], &gene1.beta[347], &gene1.beta[348], &gene1.beta[349], &gene1.beta[350], &gene1.beta[351], &gene1.beta[352], &gene1.beta[353], &gene1.beta[354], &gene1.beta[355], &gene1.beta[356], &gene1.beta[357], &gene1.beta[358], &gene1.beta[359], &gene1.beta[360], &gene1.beta[361], &gene1.beta[362], &gene1.beta[363], &gene1.beta[364], &gene1.beta[365], &gene1.beta[366], &gene1.beta[367], &gene1.beta[368], &gene1.beta[369], &gene1.beta[370], &gene1.beta[371], &gene1.beta[372], &gene1.beta[373], &gene1.beta[374], &gene1.beta[375], &gene1.beta[376], &gene1.beta[377], &gene1.beta[378], &gene1.beta[379], &gene1.beta[380], &gene1.beta[381], &gene1.beta[382], &gene1.beta[383], &gene1.beta[384], &gene1.beta[385], &gene1.beta[386], &gene1.beta[387], &gene1.beta[388], &gene1.beta[389], &gene1.beta[390], &gene1.beta[391], &gene1.beta[392], &gene1.beta[393], &gene1.beta[394], &gene1.beta[395], &gene1.beta[396], &gene1.beta[397], &gene1.beta[398], &gene1.beta[399], &gene1.beta[400], &gene1.beta[401], &gene1.beta[402], &gene1.beta[403], &gene1.beta[404], &gene1.beta[405], &gene1.beta[406], &gene1.beta[407], &gene1.beta[408], &gene1.beta[409], &gene1.beta[410], &gene1.beta[411], &gene1.beta[412], &gene1.beta[413], &gene1.beta[414], &gene1.beta[415], &gene1.beta[416], &gene1.beta[417], &gene1.beta[418], &gene1.beta[419], &gene1.beta[420], &gene1.beta[421], &gene1.beta[422], &gene1.beta[423], &gene1.beta[424], &gene1.beta[425], &gene1.beta[426], &gene1.beta[427], &gene1.beta[428], &gene1.beta[429], &gene1.beta[430], &gene1.beta[431], &gene1.beta[432], &gene1.beta[433], &gene1.beta[434], &gene1.beta[435], &gene1.beta[436], &gene1.beta[437], &gene1.beta[438], &gene1.beta[439], &gene1.beta[440], &gene1.beta[441], &gene1.beta[442], &gene1.beta[443], &gene1.beta[444], &gene1.beta[445], &gene1.beta[446], &gene1.beta[447], &gene1.beta[448], &gene1.beta[449], &gene1.beta[450], &gene1.beta[451], &gene1.beta[452], &gene1.beta[453], &gene1.beta[454], &gene1.beta[455], &gene1.beta[456], &gene1.beta[457], &gene1.beta[458], &gene1.beta[459], &gene1.beta[460], &gene1.beta[461], &gene1.beta[462], &gene1.beta[463], &gene1.beta[464], &gene1.beta[465], &gene1.beta[466], &gene1.beta[467], &gene1.beta[468], &gene1.beta[469], &gene1.beta[470], &gene1.beta[471], &gene1.beta[472], &gene1.beta[473], &gene1.beta[474], &gene1.beta[475], &gene1.beta[476], &gene1.beta[477], &gene1.beta[478], &gene1.beta[479], &gene1.beta[480], &gene1.beta[481], &gene1.beta[482], &gene1.beta[483], &gene1.beta[484], &gene1.beta[485], &gene1.beta[486], &gene1.beta[487], &gene1.beta[488], &gene1.beta[489], &gene1.beta[490], &gene1.beta[491], &gene1.beta[492], &gene1.beta[493], &gene1.beta[494], &gene1.beta[495], &gene1.beta[496], &gene1.beta[497], &gene1.beta[498], &gene1.beta[499], &gene1.beta[500], &gene1.beta[501], &gene1.beta[502], &gene1.beta[503], &gene1.beta[504], &gene1.beta[505], &gene1.beta[506], &gene1.beta[507], &gene1.beta[508], &gene1.beta[509], &gene1.beta[510], &gene1.beta[511], &gene1.beta[512], &gene1.beta[513], &gene1.beta[514], &gene1.beta[515], &gene1.beta[516], &gene1.beta[517], &gene1.beta[518], &gene1.beta[519], &gene1.beta[520], &gene1.beta[521], &gene1.beta[522], &gene1.beta[523], &gene1.beta[524], &gene1.beta[525], &gene1.beta[526], &gene1.beta[527], &gene1.beta[528], &gene1.beta[529], &gene1.beta[530], &gene1.beta[531], &gene1.beta[532], &gene1.beta[533], &gene1.beta[534], &gene1.beta[535], &gene1.beta[536], &gene1.beta[537], &gene1.beta[538], &gene1.beta[539], &gene1.beta[540], &gene1.beta[541], &gene1.beta[542], &gene1.beta[543], &gene1.beta[544], &gene1.beta[545], &gene1.beta[546], &gene1.beta[547], &gene1.beta[548], &gene1.beta[549], &gene1.beta[550], &gene1.beta[551], &gene1.beta[552], &gene1.beta[553], &gene1.beta[554], &gene1.beta[555], &gene1.beta[556], &gene1.beta[557], &gene1.beta[558], &gene1.beta[559], &gene1.beta[560], &gene1.beta[561], &gene1.beta[562], &gene1.beta[563], &gene1.beta[564], &gene1.beta[565], &gene1.beta[566], &gene1.beta[567], &gene1.beta[568], &gene1.beta[569], &gene1.beta[570], &gene1.beta[571], &gene1.beta[572], &gene1.beta[573], &gene1.beta[574], &gene1.beta[575], &gene1.beta[576], &gene1.beta[577], &gene1.beta[578], &gene1.beta[579], &gene1.beta[580], &gene1.beta[581], &gene1.beta[582], &gene1.beta[583], &gene1.beta[584], &gene1.beta[585], &gene1.beta[586], &gene1.beta[587], &gene1.beta[588], &gene1.beta[589], &gene1.beta[590], &gene1.beta[591], &gene1.beta[592], &gene1.beta[593], &gene1.beta[594], &gene1.beta[595], &gene1.beta[596], &gene1.beta[597], &gene1.beta[598], &gene1.beta[599], &gene1.beta[600], &gene1.beta[601], &gene1.beta[602], &gene1.beta[603], &gene1.beta[604], &gene1.beta[605], &gene1.beta[606], &gene1.beta[607], &gene1.beta[608], &gene1.beta[609], &gene1.beta[610], &gene1.beta[611], &gene1.beta[612], &gene1.beta[613], &gene1.beta[614], &gene1.beta[615], &gene1.beta[616], &gene1.beta[617], &gene1.beta[618], &gene1.beta[619], &gene1.beta[620], &gene1.beta[621], &gene1.beta[622], &gene1.beta[623], &gene1.beta[624], &gene1.beta[625], &gene1.beta[626], &gene1.beta[627], &gene1.beta[628], &gene1.beta[629], &gene1.beta[630], &gene1.beta[631], &gene1.beta[632], &gene1.beta[633], &gene1.beta[634], &gene1.beta[635], &gene1.beta[636], &gene1.beta[637], &gene1.beta[638], &gene1.beta[639], &gene1.beta[640], &gene1.beta[641], &gene1.beta[642], &gene1.beta[643], &gene1.beta[644], &gene1.beta[645], &gene1.beta[646], &gene1.beta[647], &gene1.beta[648], &gene1.beta[649], &gene1.beta[650], &gene1.beta[651], &gene1.beta[652], &gene1.beta[653], &gene1.beta[654], &gene1.beta[655], &gene1.beta[656], &gene1.beta[657], &gene1.beta[658], &gene1.beta[659], &gene1.beta[660], &gene1.beta[661], &gene1.beta[662], &gene1.beta[663], &gene1.beta[664], &gene1.beta[665], &gene1.beta[666], &gene1.beta[667], &gene1.beta[668], &gene1.beta[669], &gene1.beta[670], &gene1.beta[671], &gene1.beta[672], &gene1.beta[673], &gene1.beta[674], &gene1.beta[675], &gene1.beta[676], &gene1.beta[677], &gene1.beta[678], &gene1.beta[679], &gene1.beta[680], &gene1.beta[681], &gene1.beta[682], &gene1.beta[683], &gene1.beta[684], &gene1.beta[685], &gene1.beta[686], &gene1.beta[687], &gene1.beta[688], &gene1.beta[689], &gene1.beta[690], &gene1.beta[691], &gene1.beta[692], &gene1.beta[693], &gene1.beta[694], &gene1.beta[695], &gene1.beta[696], &gene1.beta[697], &gene1.beta[698], &gene1.beta[699], &gene1.beta[700], &gene1.beta[701], &gene1.beta[702], &gene1.beta[703], &gene1.beta[704], &gene1.beta[705], &gene1.beta[706], &gene1.beta[707], &gene1.beta[708], &gene1.beta[709], &gene1.beta[710], &gene1.beta[711], &gene1.beta[712], &gene1.beta[713], &gene1.beta[714], &gene1.beta[715], &gene1.beta[716], &gene1.beta[717], &gene1.beta[718], &gene1.beta[719], &gene1.beta[720], &gene1.beta[721], &gene1.beta[722], &gene1.beta[723], &gene1.beta[724], &gene1.beta[725], &gene1.beta[726], &gene1.beta[727], &gene1.beta[728], &gene1.beta[729], &gene1.beta[730], &gene1.beta[731], &gene1.beta[732], &gene1.beta[733], &gene1.beta[734], &gene1.beta[735], &gene1.beta[736], &gene1.beta[737], &gene1.beta[738], &gene1.beta[739], &gene1.beta[740], &gene1.beta[741], &gene1.beta[742], &gene1.beta[743], &gene1.beta[744], &gene1.beta[745], &gene1.beta[746], &gene1.beta[747], &gene1.beta[748], &gene1.beta[749], &gene1.beta[750], &gene1.beta[751], &gene1.beta[752], &gene1.beta[753], &gene1.beta[754], &gene1.beta[755], &gene1.beta[756], &gene1.beta[757], &gene1.beta[758], &gene1.beta[759], &gene1.beta[760], &gene1.beta[761], &gene1.beta[762], &gene1.beta[763], &gene1.beta[764], &gene1.beta[765], &gene1.beta[766], &gene1.beta[767], &gene1.beta[768], &gene1.beta[769], &gene1.beta[770], &gene1.beta[771], &gene1.beta[772], &gene1.beta[773], &gene1.beta[774], &gene1.beta[775], &gene1.beta[776], &gene1.beta[777], &gene1.beta[778], &gene1.beta[779], &gene1.beta[780], &gene1.beta[781], &gene1.beta[782], &gene1.beta[783], &gene1.beta[784], &gene1.beta[785], &gene1.beta[786], &gene1.beta[787], &gene1.beta[788], &gene1.beta[789], &gene1.beta[790], &gene1.beta[791], &gene1.beta[792], &gene1.beta[793], &gene1.beta[794], &gene1.beta[795], &gene1.beta[796], &gene1.beta[797], &gene1.beta[798], &gene1.beta[799], &gene1.beta[800], &gene1.beta[801], &gene1.beta[802], &gene1.beta[803], &gene1.beta[804], &gene1.beta[805], &gene1.beta[806], &gene1.beta[807], &gene1.beta[808], &gene1.beta[809], &gene1.beta[810], &gene1.beta[811], &gene1.beta[812], &gene1.beta[813], &gene1.beta[814], &gene1.beta[815], &gene1.beta[816], &gene1.beta[817], &gene1.beta[818], &gene1.beta[819], &gene1.beta[820], &gene1.beta[821], &gene1.beta[822], &gene1.beta[823], &gene1.beta[824], &gene1.beta[825], &gene1.beta[826], &gene1.beta[827], &gene1.beta[828], &gene1.beta[829], &gene1.beta[830], &gene1.beta[831], &gene1.beta[832], &gene1.beta[833], &gene1.beta[834], &gene1.beta[835], &gene1.beta[836], &gene1.beta[837], &gene1.beta[838], &gene1.beta[839], &gene1.beta[840], &gene1.beta[841], &gene1.beta[842], &gene1.beta[843], &gene1.beta[844], &gene1.beta[845], &gene1.beta[846], &gene1.beta[847], &gene1.beta[848], &gene1.beta[849], &gene1.beta[850], &gene1.beta[851], &gene1.beta[852], &gene1.beta[853], &gene1.beta[854], &gene1.beta[855], &gene1.beta[856], &gene1.beta[857], &gene1.beta[858], &gene1.beta[859], &gene1.beta[860], &gene1.beta[861], &gene1.beta[862], &gene1.beta[863], &gene1.beta[864], &gene1.beta[865], &gene1.beta[866], &gene1.beta[867], &gene1.beta[868], &gene1.beta[869], &gene1.beta[870], &gene1.beta[871], &gene1.beta[872], &gene1.beta[873], &gene1.beta[874], &gene1.beta[875], &gene1.beta[876], &gene1.beta[877], &gene1.beta[878], &gene1.beta[879], &gene1.beta[880], &gene1.beta[881], &gene1.beta[882], &gene1.beta[883], &gene1.beta[884], &gene1.beta[885], &gene1.beta[886], &gene1.beta[887], &gene1.beta[888], &gene1.beta[889], &gene1.beta[890], &gene1.beta[891], &gene1.beta[892], &gene1.beta[893], &gene1.beta[894], &gene1.beta[895], &gene1.beta[896], &gene1.beta[897], &gene1.beta[898], &gene1.beta[899], &gene1.beta[900], &gene1.beta[901], &gene1.beta[902], &gene1.beta[903], &gene1.beta[904], &gene1.beta[905], &gene1.beta[906], &gene1.beta[907], &gene1.beta[908], &gene1.beta[909], &gene1.beta[910], &gene1.beta[911], &gene1.beta[912], &gene1.beta[913], &gene1.beta[914], &gene1.beta[915], &gene1.beta[916], &gene1.beta[917], &gene1.beta[918], &gene1.beta[919], &gene1.beta[920], &gene1.beta[921], &gene1.beta[922], &gene1.beta[923], &gene1.beta[924], &gene1.beta[925], &gene1.beta[926], &gene1.beta[927], &gene1.beta[928], &gene1.beta[929], &gene1.beta[930], &gene1.beta[931], &gene1.beta[932], &gene1.beta[933], &gene1.beta[934], &gene1.beta[935], &gene1.beta[936], &gene1.beta[937], &gene1.beta[938], &gene1.beta[939], &gene1.beta[940], &gene1.beta[941], &gene1.beta[942], &gene1.beta[943], &gene1.beta[944], &gene1.beta[945])) {
    			
    			/*counting for how many genes */
    			count+=1;
    			
    			gene_t gene2;
    			
    			if (count>gene_num){
    				gene[count-1]=malloc(sizeof(gene2));
    				gene[count-1]=gene1;
    			}else{
    				gene[count-1]=gene1;
    			}
    	}
    gene_num is 300

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,554
    But gene isn't a pointer, or an array of pointers.
    It is just a huge array.

    Put this at the start of main, to see how big it is.
    printf("sizeof(gene) = %lu bytes\n", (unsigned long)(sizeof(gene)) );

    Also, lines 2 and 3 are simply awful code.
    Are you seriously saying you copy/pasted 900+ times?
    Use a loop!!!!
    Code:
    if ( fscanf(fp,"%s", gene1.name) == EOF ) break;  // or return 
    for ( i = 0 ; i < beta_num ; i++ ) {
      if ( fscanf(fp,"%f", &gene1.beta[i]) == EOF ) break;  // or return
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Feb 2013
    Posts
    11
    I think there is something wrong with my concept of malloc. Maybe I modify the program. Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 11-27-2012, 10:54 AM
  2. lvalue required as left operand of assignment
    By thames in forum C Programming
    Replies: 2
    Last Post: 10-30-2012, 09:43 AM
  3. lvalue required as left operand of assignment
    By ModeSix in forum C Programming
    Replies: 6
    Last Post: 04-14-2011, 12:45 PM
  4. error: lvalue required as left operand of assignment
    By owjian1987 in forum C Programming
    Replies: 5
    Last Post: 02-11-2011, 11:34 AM
  5. Replies: 3
    Last Post: 06-01-2010, 06:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21