News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

Pointer substraction

Started by Grincheux, December 11, 2021, 02:19:29 PM

Previous topic - Next topic

Grincheux

I want to replace lstrlen with following code :
char _szErrorMessage[1024] ;
LPSTR _lpszStart, _lpszError ;
_lpszError = _lpszStart = _szError ;


while(*_lpszStart++) ;


_lpszStart = _lpszStart - _lpszError ;



I get the following error:


Quoteerror #2168: Operands of '=' have incompatible types 'char *' and 'long long int'.
Why?

Could someone help me?

Grincheux

Quote from: Grincheux on December 11, 2021, 02:19:29 PM
I want to replace lstrlen with following code :
   char   _szErrorMessage[1024] ;
LPSTR   _lpszStart, _lpszError ;
   _lpszError = _lpszStart = _szError ;

   while(*_lpszStart++) ;

   _lpszStart = _lpszStart - _lpszError ;


I get the following error:

Quoteerror #2168: Operands of '=' have incompatible types 'char *' and 'long long int'.

Why?

Could someone help me?


frankie

What you are trying to do?
What is _lpszError?
The error is due to the fact that the difference between 2 pointers is an integer, that you are trying to assign back to _lpszStart that is a pointer to char.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Grincheux

I am counting the difference between the start of the string and the place where the pointer finds '\0'


But you are right. I looked at the operation and not where I stored the result.


Thank You Frankie