Pelles C forum

C language => Beginner questions => Topic started by: Grincheux on December 11, 2021, 02:19:29 PM

Title: Pointer substraction
Post by: Grincheux 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?
Title: Re: Pointer substraction
Post by: Grincheux 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?

Title: Re: Pointer substraction
Post by: frankie 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.
Title: Re: Pointer substraction
Post by: Grincheux 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