'++' needs l-value

This is a discussion on '++' needs l-value within the C Programming forums, part of the General Programming Boards category; Code: char inputTextArray[5000]; char currentCharacter; //current character input from the file while((currentCharacter = getc(fp1)) != EOF) { *inputTextArray = currentCharacter; ...

  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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,172
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,172
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

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