-
'++' 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: but I am still getting the same error.
What do i need to do to correct this error?
-
You cannot use ++ on an array. You must use it on an element, a char.
Either you do inputTextArray[n]++ or (*inputTextArray)++.
-
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
}
-
Oh and, to advance to a new position using ++ can only be done via pointers, as mike_g shows you.