This is a simple issue that I would want to know about it.
int memcmp(void *s1, void *s2, int n);
void suppous void right? I can use any type so..
I suppose that i can compare char* with const char * pointer and to the contrary the compiler return is... Ilegal pointer.
Which is the right function to compare a string RAM memory with string ROM memory?
What about int strncmp(char *s1, char *s2, char len);
why I cant cast in this function ej:
char x[]="abdc";
const char y[]="abcdFGHI";
int strncmp(x, (char *)y, 4); //It in mikroC doesnot work.
Any idea? Regards
Alejandro
Complile Issuer (memcmp, strcmp)
-
- Posts: 68
- Joined: 17 Jan 2008 19:32
- Location: Venezuela
- Contact:
- lana.arsic
- mikroElektronika team
- Posts: 1715
- Joined: 15 Jan 2016 12:50
Re: Complile Issuer (memcmp, strcmp)
Hi Alejandro,
I have tested your code and both functions memcmp and strncmp compile without error
and give appropriate results if you are comparing char with const char.
Can you tell me which MCU, compiler and version of the compiler do you use?
Best regards,
Lana
I have tested your code and both functions memcmp and strncmp compile without error
and give appropriate results if you are comparing char with const char.
Can you tell me which MCU, compiler and version of the compiler do you use?
Best regards,
Lana
-
- Posts: 68
- Joined: 17 Jan 2008 19:32
- Location: Venezuela
- Contact:
Re: Complile Issuer (memcmp, strcmp)
Hi Lana.
Thank you for you soon answer
MicroC 6.6.3 PIC18F87J60
this is my code
char * pcStringCommand = "help arg1 arg2 arg3";
const char * const pcCommand ="help";
strcmp(pcStringCommand, pcCommand); //it does not compile
strncmp(pcStringCommand, pcCommand, strlen(pcCommand)); //it does not compile
memcmp(pcStringCommand, pcCommand, strlen(pcCommand)); //it does not compile neither
Could you copy/paste your code here. I appreciate it.
Regards
Alejandro
Thank you for you soon answer
MicroC 6.6.3 PIC18F87J60
this is my code
char * pcStringCommand = "help arg1 arg2 arg3";
const char * const pcCommand ="help";
strcmp(pcStringCommand, pcCommand); //it does not compile
strncmp(pcStringCommand, pcCommand, strlen(pcCommand)); //it does not compile
memcmp(pcStringCommand, pcCommand, strlen(pcCommand)); //it does not compile neither
Could you copy/paste your code here. I appreciate it.
Regards
Alejandro
Re: Complile Issuer (memcmp, strcmp)
Hi,
I see the issue now, Lana probably tried constant pointer instead of of pointer to constant.
Due to the architecture specifics, the pointers to RAM and ROM are not compatible, so the compiler issues an error due to this.
To solve this, you can do one of these things :
1. Copy string from ROM to RAM,
2. Use comparing function that handles ROM strings.
Regards,
Filip.
I see the issue now, Lana probably tried constant pointer instead of of pointer to constant.
Due to the architecture specifics, the pointers to RAM and ROM are not compatible, so the compiler issues an error due to this.
To solve this, you can do one of these things :
1. Copy string from ROM to RAM,
2. Use comparing function that handles ROM strings.
Regards,
Filip.
-
- Posts: 68
- Joined: 17 Jan 2008 19:32
- Location: Venezuela
- Contact:
Re: Complile Issuer (memcmp, strcmp)
Hi Filip.
Thanks for your reply.
Yeap. That's what Im doing. So I worder if I could do a casting like (char*) or something. But I see that not.
Regards for your support.
Alejandro
Thanks for your reply.
Yeap. That's what Im doing. So I worder if I could do a casting like (char*) or something. But I see that not.
Regards for your support.
Alejandro