Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

my hitech compiler is generating warninig illegal conversion of pointer to

Status
Not open for further replies.

zia

Full Member level 5
Joined
Sep 24, 2010
Messages
284
Helped
27
Reputation
54
Reaction score
26
Trophy points
1,318
Location
Islamabad Pakistan
Activity points
2,746
(warning is illegal conversion of pointer to integer)
char *pch;
char j=0;
pch=strchr(Rx1Buffer,'$');
j=pch;
 

zia

Full Member level 5
Joined
Sep 24, 2010
Messages
284
Helped
27
Reputation
54
Reaction score
26
Trophy points
1,318
Location
Islamabad Pakistan
Activity points
2,746
u r right but i not getting accurate value of j. suppose *pch="123$asdfnbx is " if i am using
pch=strchr(Rx1Buffer,'$');
j=pch;
then it must have to give j=3 or j=4 as according to position but it gives different value as like 156 etc.
 

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
try to change
Code:
 pch=strchr(Rx1Buffer,'$');
to
Code:
 *pch=strchr(Rx1Buffer,'$');
Can you tell what does strchr(Rx1Buffer,'$'); function do?
 

zia

Full Member level 5
Joined
Sep 24, 2010
Messages
284
Helped
27
Reputation
54
Reaction score
26
Trophy points
1,318
Location
Islamabad Pakistan
Activity points
2,746
function
strchr
<cstring>
const char * strchr ( const char * str, int character );
char * strchr ( char * str, int character );
Locate first occurrence of character in string
Returns a pointer to the first occurrence of character in the C string str.

The terminating null-character is considered part of the C string. Therefore, it can also be located in order to retrieve a pointer to the end of a string.

Parameters
str
C string.
character
Character to be located. It is passed as its int promotion, but it is internally converted back to char for the comparison.

Return Value
A pointer to the first occurrence of character in str.
If the character is not found, the function returns a null pointer.

Portability
In C, this function is only declared as:

char * strchr ( const char *, int );

instead of the two overloaded versions provided in C++.

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* strchr example */
#include <stdio.h>
#include <string.h>

int main ()
{
char str[] = "This is a sample string";
char * pch;
printf ("Looking for the 's' character in \"%s\"...\n",str);
pch=strchr(str,'s');
while (pch!=NULL)
{
printf ("found at %d\n",pch-str+1);
pch=strchr(pch+1,'s');
}
return 0;
}


Output:

Looking for the 's' character in "This is a sample string"...
found at 4
found at 7
found at 11
found at 18
 

zuisti

Advanced Member level 1
Joined
Jul 2, 2004
Messages
480
Helped
188
Reputation
376
Reaction score
182
Trophy points
1,323
Location
Hungary
Activity points
3,281
(warning is illegal conversion of pointer to integer)
char *pch;
char j=0;
pch=strchr(Rx1Buffer,'$');
j=pch; // ????
As can be seen in your example, the correct solution is:

j = pch - Rx1Buffer ; // + 1 (if the first pos is equal to 1)
 
  • Like
Reactions: zia

    zia

    points: 2
    Helpful Answer Positive Rating

zia

Full Member level 5
Joined
Sep 24, 2010
Messages
284
Helped
27
Reputation
54
Reaction score
26
Trophy points
1,318
Location
Islamabad Pakistan
Activity points
2,746
j = pch - Rx1Buffer ;
working fine
but plz help me to understand zuisti,plz.
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,861
Helped
14,120
Reputation
28,497
Reaction score
12,801
Trophy points
1,393
Location
Bochum, Germany
Activity points
277,790
Besides the erroneous j = pch, I'm unable to locate a problem or question addressed in your posts.
 

Joined
Jul 25, 2012
Messages
1,192
Helped
170
Reputation
340
Reaction score
161
Trophy points
1,343
Activity points
0
char *strchr(char *ptr, char chr);

Description Function locates the first occurrence of character chr in the string ptr. The function returns a pointer to the first occurrence of character chr, or a null pointer if chr does not occur in ptr. The terminating null character is considered to be a part of the string.

Example
Code:
 char txt[] = "PIC18F4550";
char *res;

res = strchr(txt, '4');  // routine will locate the character '4' in the 'txt' string, and return the address of the character

Code:
 pch=strchr(Rx1Buffer,'$');
here '$' is searched and the address of '$' character in Rx1Buffer is assigned to pointer pch

If Rx1Buffer starts at address 0x00 and the location of '$' character in the RxBuffer is at address 0x08 then pch will be equal to 0x08


@zuisti

Can we write
Code:
 j = pch - Rx1Buffer ;
as
Code:
 j = strchr(Rx1Buffer,'$') - Rx1Buffer ;
?????
 
Last edited:
  • Like
Reactions: zia

    zia

    points: 2
    Helpful Answer Positive Rating

zuisti

Advanced Member level 1
Joined
Jul 2, 2004
Messages
480
Helped
188
Reputation
376
Reaction score
182
Trophy points
1,323
Location
Hungary
Activity points
3,281
@zuisti
Can we write
Code:
 j = pch - Rx1Buffer ;
as
Code:
 [COLOR="#FF0000"]j = strchr(Rx1Buffer,'$') - Rx1Buffer ;[/COLOR]
?????
Yes, of course it is also a possible (and more elegant) solution but only if the first matched character's position is wanted, else use the intermediate 'pch' variable too (in a loop as in the example).
 
  • Like
Reactions: zia

    zia

    points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top