Thread: invalid lvalue in assignment

  1. #1
    C_newbie
    Join Date
    Oct 2005
    Location
    Greece
    Posts
    32

    invalid lvalue in assignment

    Hello,
    I have an int array and want to print it by using a function called PrintTable.
    PrintTable has to print the numbers of the array, 12 at every row.
    I get this error message
    Code:
    ask.c: In function `PrintTable':
    ask.c:64: error: invalid lvalue in assignment
    And here you have my function:
    Code:
    void PrintTable(int T[], int Last)
    {
    int i;
    for(i=0; i<=Last; ++i)
    {       if(fmod(i,12)=0)  //this is line 64
                    printf("%4d\n",T[i]);
            else
                    printf("%4d",T[i]);
    }
    }
    Please help me, what does this error mean? Where is the mistake?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > for(i=0; i<=Last; ++i)
    If last is counting the number of elements in the array, this should be
    for(i=0; i<Last; ++i)

    > if(fmod(i,12)=0)
    Use ==, not =
    Besides, these are integers, so
    if ( i % 12 == 0 )
    is much better
    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.

  3. #3
    Registered User cbastard's Avatar
    Join Date
    Jul 2005
    Location
    India
    Posts
    167
    ask.c:64: error: invalid lvalue in assignment
    Error is because of this.
    Code:
    if(fmod(i,12)=0)
    You are assigning value to the function fmod.Use == operator in that as already told by salem.
    Long time no C. I need to learn the language again.
    Help a man when he is in trouble and he will remember you when he is in trouble again.
    You learn in life when you lose.
    Complex problems have simple, easy to understand wrong answers.
    "A ship in the harbour is safe, but that's not what ships are built
    for"

  4. #4
    C_newbie
    Join Date
    Oct 2005
    Location
    Greece
    Posts
    32

    Thanks a lot.

    Thanks a lot!
    Finally my programm got compiled, thanks to you!
    Now I have other problems. I get a lot of ununderstanding numbers printing on the screen, and at the end the message segmantation fault.
    I will copy my whole programm, but I think the mistake has to do with the pointers which I can't understand very well.
    Code:
    #include <stdio.h>
    
    #define MaxSize 300
    #define First 0
    
    void PrintTable(int T[], int Last);
    void Insert(int T [], int elem, int pos, int* Last);
    void Delete(int T[],int pos, int* Last);
    void DeleteMult(int T[], int* Last);
    
    main()
    {
    int *Last;
    int T[MaxSize];
    
    int l, elem, pos;
            //Reading the table
    FILE *pT;
    pT = fopen("tab.dat","r");
    Last=&T[0];
            //Printing the table                      <<<<----------------------Where the problem starts
    PrintTable(T, *Last);
    //-----------------------------------------------------------------------------------------------//
            //Dialog between Computer-User
    printf("Which application do you want to use?:\n1-> Insert \n2->Delete \n3->DeleteMult\n Please give the number");
    printf("of the application:");
    scanf("%i",&l);
    printf("\n");
            //Dialog for Insert
    if (l=1)
    {
            printf("Please give the number you want to insert:");
            scanf("%i",&elem);
            printf("\nAnd the place for it to be inserted:");
            scanf("%i",&pos);
           Insert(T, elem, pos, Last);
            printf("\nThe element has been inserted\n");
            PrintTable(T, *Last);
    }
         //Dialog for Delete
    else if (l=2)
    {
            printf("Please give the number you want to delete:");
            scanf("%i",&pos);
            Delete(T, pos, Last);
            printf("\nThe element has been deleted\n");
            PrintTable(T, *Last);
    }
            //Dialog for DeleteMult
    else if (l=3)
    {
            DeleteMult(T, Last);
            printf("The application is finished\n");
            PrintTable(T, *Last);
    }
    else
            //If the application number is false:
            printf("The application number can only be 1 2 i 3\n");
    //-----------------------------------------------------------------------------------------
    }
    
    
    //*******************************************************//
    //*********************FUNCTIONS*************************//
    //*******************************************************//
    
    void PrintTable(int T[], int Last)
    {
    int i;
    for(i=1; i<Last; ++i)
    {       if(i%12==0)
                    printf("%4d\n",T[i],"\v");
            else
                    printf("%4d",T[i],"\v");
    }
    }
    
    
    //////////////////////////////////////////////////////
    void Insert(int T[], int elem, int pos, int *Last)
    {
    int i;
    if(pos>=First & pos<=*Last & *Last<MaxSize)
    {       for (i=*Last; i=pos; i--)
            {
                    T[i+1]=T[i];
            }
      T[pos]= elem;
      Last= Last+1;
    
    }
    else
            printf("I thesi pos vrisketai ektos tou pinaka T\n");
    }
    
    
    //////////////////////////////////////////////////////
    void Delete(int T[], int pos, int* Last)
    {
    int i;
            if(pos=*Last)
              {
                    T[pos]=0;
                    *Last=*Last-1;
    
              }
            else if (pos<*Last & pos >=First)
              {
                      for(i=pos; i=pos-1; ++i)
                      T[i]=T[i+1];
    
            Last=Last-1;
    
              }
            else
                    printf("Den Iparxei stoixeio se aythn thn thesi i den iparxei i thesi ston pinaka\n");
    }
    
    
    ///////////////////////////////////////////////////////
    void DeleteMult(int T[], int* Last)
    {
    int i, k;
    for(i=First+1; i<=*Last; ++i)
            for(k=First; k<=i-1; ++k)
                            if(T[i]=T[k])
                            Delete( T, i, Last);
    
    }
    Thats it! Sorry for posting so much code.
    I can't upload the data file, but it has 256 numbers, the first is not for the table, it is the number 255 which says us how many numbers the file has. So Last must be the T[255] at the start.

    Sorry, again, and I hope that you help me!

  5. #5
    Registered User cbastard's Avatar
    Join Date
    Jul 2005
    Location
    India
    Posts
    167
    Oh No,not again.
    Code:
    if (l=1)
    else if (l=2)
    else if (l=3)

    Code:
    if(pos>=First & pos<=*Last & *Last<MaxSize)
    Are you sure you want & not && because there is difference between them.
    Next time post the error which you get while compiling and highlight the line associated with it.
    Long time no C. I need to learn the language again.
    Help a man when he is in trouble and he will remember you when he is in trouble again.
    You learn in life when you lose.
    Complex problems have simple, easy to understand wrong answers.
    "A ship in the harbour is safe, but that's not what ships are built
    for"

  6. #6
    C_newbie
    Join Date
    Oct 2005
    Location
    Greece
    Posts
    32
    Thanks cbastard
    Yeah the && is right. Thanks
    The problem is that I don't get any message at compilation. The problem is that when I run the programm, I get:
    Code:
    bash-2.05b$ ./ask
       01073824184   2   11073824184   01073831240   1   1   010738300241073825496
    10737432161073743606  20107374240010737418241345133401345133401073824184   21073825468   0   0
    -107374513210737914501073936980   0   0   01073800667   01075064960  15-10737451041073743876
     208   110737951641075064928   0  3210750649201075052736   8   210738313041075066068
    10737712771073831936537721073825468-107374453210737496701073825840   0   0   0   0   0
       0   0   01073831304   0   0   0   0   0   010738125581073812560
    10738240961073830024-1073744608   0   0   0   0   01073824184   0   0   0
       0   0   0   0   0   0   0   0   0  641073830712  15
    -7664-67201073825568   0   3196608-81401073829400  96  16134513148134513020
       0   0   01345198721073825864   0   0   0   0107506496016777216  -1
       0   0   0   0   0   1   0   0   0   0   0   0
       0   0   0   610750649601048575  81   0   0   0   0   0
       0   0   0   0   0   0   0   0   0   0   0   0
       0   0   0   0   0   0   016685724637783332311882091379186937483425697
       0   0   0   0   0   0   0   0   0   010737450671073825468
    134512692   0-10737440001073798214134512692   7-1073744480   4-1073744346-7168  -1   0
       0   71345126921345134881970170188 120   0   0   0   0   0   0
       0   0   0   0   0   0   0   01886416896186228434329811   0
       0   0   0   0   0   0   0   0   0   0   0   0
    775028736
    Poia leitourgia thelete na ektelesete?:
    1-> Insert
    2->Delete
    3->DeleteMult
     Parakalo eisagete ton arithmotis leitourgias:1
    
    Parakalo eisagete to stoixeio pou thelete na eisagete (akairaios):2
    
    Kai tin thesi pou thelete na eisaxthei to stoixeio (akaireos):3
    I thesi pos vrisketai ektos tou pinaka T
       01073824184   2   11073824184   01073831240   1   1   010738300241073825496
    10737432161073743606  20107374240010737418241345133401345133401073824184   21073825468   0   0
    -107374513210737914501073936980   0   0   01073800667   01075064960  15-10737451041073743876
     208   110737951641075064928   0  3210750649201075052736   8   210738313041075066068
    10737712771073831936537721073825468-107374453210737496701073825840   0   0   0   0   0
       0   0   01073831304   0   0   0   0   0   010738125581073812560
    10738240961073830024-1073744608   0   0   0   0   01073824184   0   0   0
       0   0   0   0   0   0   0   0   0  641073830712  15
    -7664-67201073825568   0   3196608-81401073829400  96  16134513148134513020
       0   0   01345198721073825864   0   0   0   0107506496016777216  -1
       0   0   0   0   0   1   0   0   0   0   0   0
       0   0   0   610750649601048575  81   0   0   0   0   0
       0   0   0   0   0   0   0   0   0   0   0   0
       0   0   0   0   0   0   016685724637783332311882091379186937483425697
       0   0   0   0   0   0   0   0   0   010737450671073825468
    134512692   0-10737440001073798214134512692   7-1073744480   4-1073744346-7168  -1   0
       0   71345126921345134881970170188 120   0   0   0   0   0   0
       0   0   0   0   0   0   0   01886416896186228434329811   0
       0   0   0   0   0   0   0   0   0   0   0   0
    7750287367754337828085292017038061   0   01811939436 108-10737442881073789577134513184215818
    215818-1073744192107377188910739576421345132561700208641169994659654054923280912158510738308401397030914808591444
    13360   0  32   0   01073957836107393733210739024681073830024   310738307121073830760
    1073825468107382628024641422-1073744024107377284813451322824641422134513052-10737440921073826200   11073830760
       1   0   11073826200   0-1073744092   0   0   0   0   0-1073743984
    1073825864134513228   0   0134519940-1073744072134513393   0   0-1073744040134514778   0
    1075053080134519708-1073745264   01073824832-10737439441073974944   1-1073743900-107374389210737852841075053080
       0-1073744016-1073743944-10737440321073974882   0   0   01073825468   1134513488   0
    107378572810737874401073825468   1134513488   0134513521134513660   1-1073743900134514752134514832
    1073787440-10737439081073812811   1-1073743487   0-1073743481-1073743462-1073743447-1073743427-1073743410-1073743392
    -1073743373-1073743362-1073743346-1073743333-1073743319-1073743243-1073743106-1073743080-1073742956-1073742927-1073742909-1073742892
    -1073742870-1073742850-1073742828-1073742814-1073742800-1073742789-1073742770-1073742718-1073742675-1073742643-1073742613-1073742591
    -1073742521-1073742503-1073742488-1073742464-1073742447-1073742394-1073742373-1073742344-1073742324-1073742313-1073742266-1073742235
    -1073742214-1073742191-1073742183-1073742163-1073742145-1073742123-1073742105-1073742082-1073742073-1073742056-1073742041-1073742007
    -1073741965-1073741953-1073741940-1073741926-1073741905-1073741894-1073741856-1073741842   0  32-7168  33
    -8192  161072430079   64096  17 100   3134512692   4  32   5
       7   71073741824   8   0   9134513488  11 500  12 500  13
     500  14 500  23   0  15-1073743492   0   0   09096536091630481920
    1275095923126375200579254970179504701319360266701129054323134645769516985175731398103918116210355212806587831162365268
    171529120117020632011598245888138020563310288709811432317541112905429113138199991380013125185212860154613431414745928
    116269089416682465891869114465140931595510284775091919251576121339914910284104371852400175193576196711290543121431262047
    11453899061207972157139803527310279552738084644331296324608131290249511453909131635135293197041752216855980621819566957
    18353009117620824031831612474168528931320364280761932291686168436745919872773561701653604168502283616344932451667855219
    1263814400112947179412798705597925481657960298131918986355175244477319360269811818314543796489825762016871791686706
    191964477516975939551731158900841837428173114577416684429961869098810188215434918699032127960907341802790702841835378
    7923425741701670760197004087916346274441798188915193248598817019948561852793647795306342191964477512973507551380533328
    1869098813188215434918699032127960907347368052159877229511806482741397050441193705964517523792507951775691835362420
    1194292069201965065719529194171952919403979595883166857246318027907031802790703792355698170167076019700408791634627444
    17310800511668442996186909881018821543491869903212796090734170107985416342351831664050546176832062319529193996517355
    128131565579254381717016707601970040879163462744417143028351937010287131342924812304586929429476528926134261275081520
    14311995551230128461185212857954613431346653263792544343170167076019700408791634627444141459467510288028841920169263
    16510761438632691671145765935143067526913987543801230197573195017479966492021380275029197004089316346274441129840755
    133086062912302006584015450113032071613809285911275084115116315731512132201721027952207143231754111630674751330205523
    10955897101162297678186936456279563197116339065401936681068194925221277486090975951392920201754778923515351330315315
    128026708611285543091144868943138099488317978097651869835887875390316741423152193661732369451275113975096321213481296
    1937059645175237925079517756916339065406238631481311059820122901632019828073721932489313181924235217679926231819291500
    185279806911408802251414222661139875540712301975738093241111162103601141356646419660301521647276659792358505980314466
    19201692631852400175193705964218693610107956319719803144661920169263825317423164726126697618698519201692631835099951
    127509795711626985631195463507169851782913981039181128616704159837858111632817403292492123097991614144156841128875593
    133020576118521285905461343113031662010955193111698514260139810391813138193921162628947132980847911630917921330205523
    1128545614169989332718692936701819243374808725861193227602417691738618250609751313407017138125857616975946911764713332
    19538535501342202738792544343170167076019700408791634627444185107646718667395617562605114604783211624300251077760850
    184951946566474071196310860160107039712079808851599097925146481619410288018751668114027185213988418863309961917873765
    181884683117023058931869767266185240459914984152071313818708138001313910286749001668572463195411563119198401042037395043
    159824588813967865091296388693102893523714323175411229455443132981256313307955981734950220170199844619367499241279808256
    842878038129704140817479263417951763031953852528193576510313129021441195464007185212858197853987114764232691397904707
    14155331351162691912171792082919532649931329809152141553006212292137731949252946140931492579254740517016707601970040879
    16346274441836330867116260875275899374712750882051095649103188306362918699032127561582113031662011628936521601070397
    127508974913308608691028539728193705970817680423541701588846176897726719324204641931812968133079091213802750311835428669
    170140784318643979341349412208176832088219986118201919050341176917489511408771661414222661179918036711408766441280332617
    97709907331575521415529292102795194514323175411598488659126348960211806510771313164361139705068911240860771380928591
    12972373321096286269133014024514986960181869098813188215434918699032127960907341969313838191990386079596571314865996
    Segmentation fault
    It's driving me nuts. Please help!
    AC/DC: Highway to Hell!
    No speed limit, no stop signs, nobody 's gonna slow me down!

  7. #7
    Registered User cbastard's Avatar
    Join Date
    Jul 2005
    Location
    India
    Posts
    167
    The output looks like the theme of matrix. .
    well,Have you initialized the array t[] before using it otherwise it will contain junk values and only the god knows what it wil print.
    **try using some small array to check the format of the table you want to print
    Long time no C. I need to learn the language again.
    Help a man when he is in trouble and he will remember you when he is in trouble again.
    You learn in life when you lose.
    Complex problems have simple, easy to understand wrong answers.
    "A ship in the harbour is safe, but that's not what ships are built
    for"

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Code:
    if(pos=*Last)
    Lots of others, too . . . check for typos like that.

    Code:
    main()
    {
    int *Last;
    int T[MaxSize];
    
    int l, elem, pos;
            //Reading the table
    FILE *pT;
    pT = fopen("tab.dat","r");
    Last=&T[0];
    
    /* Somewhere in here you should initialize T! */
    
            //Printing the table                      <<<<----------------------Where the problem starts
    PrintTable(T, *Last);
    You're getting all that weird output because T is not initialized.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    C_newbie
    Join Date
    Oct 2005
    Location
    Greece
    Posts
    32
    I would like to thank everybody, here. My code finally runs as he should!!!
    AC/DC: Highway to Hell!
    No speed limit, no stop signs, nobody 's gonna slow me down!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. :523: error: invalid lvalue in assignment
    By nasim751 in forum C Programming
    Replies: 10
    Last Post: 04-14-2008, 04:08 AM
  2. invalid lvalue in assignment
    By saipkjai in forum C++ Programming
    Replies: 8
    Last Post: 06-21-2007, 03:19 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM