Thread: '++' needs l-value

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    47

    '++' needs l-value

    Code:
    	char inputTextArray[5000];
    	char currentCharacter;		//current character input from the file
    
    	while((currentCharacter = getc(fp1)) != EOF)
    	{
    		*inputTextArray = currentCharacter;
    		inputTextArray++; // ERROR HERE
    	}
    I get the error:
    Code:
    Error	5	error C2105: '++' needs l-value
    I tried:
    Code:
    *inputTextArray++;
    but I am still getting the same error.

    What do i need to do to correct this error?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You cannot use ++ on an array. You must use it on an element, a char.
    Either you do inputTextArray[n]++ or (*inputTextArray)++.
    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
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    You will want to copy the pointer to inputTextArray before you increment it. Otherwise you are goiing to mangle your only string pointer. Something like:
    Code:
    	char inputTextArray[5000];
    	char currentCharacter;		//current character input from the file
            char *chPtr = inputTextArray;
    	while((currentCharacter = getc(fp1)) != EOF)
    	{
    		*chPtr = currentCharacter;
    		chPtr++; // ERROR HERE
    	}

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Oh and, to advance to a new position using ++ can only be done via pointers, as mike_g shows you.
    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.

Popular pages Recent additions subscribe to a feed