!value required as left operand of assignment

This is a discussion on !value required as left operand of assignment within the C Programming forums, part of the General Programming Boards category; Its the problem with my loop part. How do I fix this? Code: #include <stdio.h> /* Define constant NUM_FIBON (number ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    29

    !value required as left operand of assignment

    Its the problem with my loop part. How do I fix this?
    Code:
    #include <stdio.h>
    
    /* Define constant NUM_FIBON (number of fibonacci numbers) to be, say, 12 */
    #define NUM_FIBON 12 
    int main()
    {
     	/* Declare and initialise an int array with the first 2 fibonacci numbers 1 and 1 */
    	/* The size of the array should be NUM_FIBON. */
    	int fibonacci[NUM_FIBON] = {1, 1};
    
    	/* Display the purpose of the program */
    	printf("\nThis program displays the first %d fibonacci numbers\n", NUM_FIBON);
    	   
    	/* Populate the array with other fibonacci numbers, starting with the 3rd number */
    	/* Each fibonacci number is the sum of the previous two */
    	for (NUM_FIBON = 2; NUM_FIBON<=12; NUM_FIBON++)
    	  {
       	   fibonacci[NUM_FIBON] = fibonacci[NUM_FIBON-1] + fibonacci[NUM_FIBON-2];
    	  }

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Hint: a #define resolves to plain text substitution (eg: after the preprocessor has passed through the code, the macro is replaced by whatever you defined it as (also known as macro expansion)). In other words:

    Code:
    #define STUFF char* p
    
    int main( void )
    {
        STUFF;
        STUFF;
    }
    
    // after expansion:
    
    int main( void )
    {
        char* p;
        char* p; // error: redeclaration of 'p'
    }
    hth.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,915
    Your code, after the preprocessor has run:
    Code:
    #include <stdio.h>
    
    /* Define constant NUM_FIBON (number of fibonacci numbers) to be, say, 12 */
    int main()
    {
     	/* Declare and initialise an int array with the first 2 fibonacci numbers 1 and 1 */
    	/* The size of the array should be NUM_FIBON. */
    	int fibonacci[12] = {1, 1};
    
    	/* Display the purpose of the program */
    	printf("\nThis program displays the first %d fibonacci numbers\n", 12);
    	   
    	/* Populate the array with other fibonacci numbers, starting with the 3rd number */
    	/* Each fibonacci number is the sum of the previous two */
    	for (12 = 2; 12<=12; 12++)
    	  {
       	   fibonacci[12] = fibonacci[12-1] + fibonacci[12-2];
    	  }
    I don't know about you, but some parts of the code doesn't make sense to me.
    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.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    29
    thkx 4 ur help Elysia

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Note also that after you correctly use a local variable as the loop counter, your loop should have < NUM_FIBON as the ending condition, not <= NUM_FIBON or you'll have a buffer overrun. Array indexes go from 0 to N-1
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 03:34 AM
  2. Replies: 1
    Last Post: 10-27-2006, 02:21 PM
  3. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  4. Please help me
    By teedee46 in forum C++ Programming
    Replies: 9
    Last Post: 05-07-2002, 12:28 AM
  5. still cany suss out this balancing problem
    By korbitz in forum C Programming
    Replies: 1
    Last Post: 01-05-2002, 09:42 AM

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