NO

Author Topic: Pointer substraction  (Read 1312 times)

Grincheux

  • Guest
Pointer substraction
« on: December 11, 2021, 02:19:29 PM »
I want to replace lstrlen with following code :
Code: [Select]
char _szErrorMessage[1024] ;
LPSTR _lpszStart, _lpszError ;
_lpszError = _lpszStart = _szError ;


while(*_lpszStart++) ;


_lpszStart = _lpszStart - _lpszError ;


I get the following error:


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

Could someone help me?

Grincheux

  • Guest
Re: Pointer substraction
« Reply #1 on: December 11, 2021, 02:21:09 PM »

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

   while(*_lpszStart++) ;

   _lpszStart = _lpszStart - _lpszError ;


I get the following error:

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

Why?

Could someone help me?


Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: Pointer substraction
« Reply #2 on: December 11, 2021, 04:05:51 PM »
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

  • Guest
Re: Pointer substraction
« Reply #3 on: December 11, 2021, 04:09:09 PM »
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