3 errors(L value and illegal use of pointer)

This is a discussion on 3 errors(L value and illegal use of pointer) within the C Programming forums, part of the General Programming Boards category; Code: #include<stdio.h> #include<conio.h> void main() { float x[20],fx[20],dd[20][20],z,value,k=1; int n,i,j; clrscr(); printf("Enter the no. of interpolating points "); scanf("%d",&n); for(i=0;i<n;i++) ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    21

    3 errors(L value and illegal use of pointer)

    Code:
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
     float x[20],fx[20],dd[20][20],z,value,k=1;
     int n,i,j;
     clrscr();
     printf("Enter the no. of interpolating points ");
     scanf("%d",&n);
     for(i=0;i<n;i++)
     {
      printf("\nEnter the values of x and f(x) ");
      scanf("%f%f",&x[i],&fx[20]);
      fflush(stdin);
     }
     value=fx[0];
     printf("\nEnter the point at which you wish to find the value ");
     scanf("%f",&z);
     for(i=0;i<n-1;i++)
     {
      dd[i,0]=(fx[i+1]-fx[i])/(x[i+1]-x[i]);
     }
     for(j=0;j<n-1;j++)
     {
      for(i=0;i<n-j-1;i++)
      {
       dd[i,j]=(dd[i+1,j]-dd[i,j])/(x[i+j+1]-x[i]);
      }
     }
     for(i=0;i<n-1;i++)
     {
      for(j=0;j<i+1;j++)
       k=k*(z-x[j]);
      value=value+(dd[0,i]*k);
     }
     printf("\nThe value is %f",value);
     getch();
    }
    The above program is showing the following errors in the lines "i have bolded"
    1)L value required
    2)L value required
    3)Illegal use of pointer in function main()

    Please help me..and please tell me everything about L value as well..

    Reply soon.

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    To access elements in a 2D array, you do: array_name[n1][n2] NOT array_name[n1, n2]. Because the later is illegal, it yields an error so the compiler cannot parse it, which in turns yields an "invalid L value" or "L value required" error because there's no valid expression on the left hand of the "=" sign. That goes for all the errors.
    Void main is non-standard, so also read the following link: http://cpwiki.sourceforge.net/Void_main
    And flushing stdin is undefined. This link contains a defined way of flushing the input buffer: http://apps.sourceforge.net/mediawik...=Pause_console
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    I believe L just refers to "left". The one you are using
    Code:
     dd[i,j]
    Is not proper C syntax. I think you mean dd[i][j]. You have the same problem on the right side of your pointer assignment.

    Here I found a quote:
    Quote Originally Posted by www.embedded.com/story/OEG20010518S0071
    the left and right operands of an assignment expression are themselves expressions. For the assignment to be valid, the left operand must refer to an object-it must be an lvalue. The right operand can be any expression. It need not be an lvalue.
    Last edited by MK27; 02-21-2009 at 07:56 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User
    Join Date
    Jan 2009
    Posts
    21
    Thx a lot guys..

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,593
    Quote Originally Posted by Elysia
    Because the later is illegal, it yields an error so the compiler cannot parse it, which in turns yields an "invalid L value" or "L value required" error because there's no valid expression on the left hand of the "=" sign. That goes for all the errors.
    Quote Originally Posted by MK27
    The one you are using (...) Is not proper C syntax.
    Actually, dd[i,0], dd[i,j] and dd[0,i] is legal C syntax, and is effectively the same as writing dd[0], dd[j] and dd[i] respectively (i.e., the comma operator is in use here). However, dd[0] and dd[j] are arrays, thus they are not lvalues and it is illegal to assign to them. In the third case, the array is converted to a pointer to its first element, thus there is an attempt to multiply a pointer by a float.
    Last edited by laserlight; 02-22-2009 at 12:46 AM.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

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