NO

Author Topic: Pointer substraction  (Read 784 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: 1941
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.

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