|
|
View previous topic :: View next topic |
Author |
Message |
eugeneb Guest
|
stricmp() |
Posted: Thu May 29, 2003 10:13 am |
|
|
If I can do this:
if (strcpy(w_cmd, "wexit"))
Why can't I do this?
if (!stricmp(w_cmd, "wexit"))
// Results in bad experession syntax on "wexit"
I am using get_string(...) to capture a 6 byte string. I then need to compare the string to available commands.
pseudo... if (w_cmd==some_cmd) then...
I can do this:
char wexit[6]="wexit";
...
if (!stricmp(w_cmd, wexit))...
but this method could tie up 100's of bytes of RAM.
I am using CCS PCH v3.158 for a 18F6720.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514852 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: stricmp() |
Posted: Thu May 29, 2003 11:23 am |
|
|
:=If I can do this:
:= if (strcpy(w_cmd, "wexit"))
:=
:=Why can't I do this?
:= if (!stricmp(w_cmd, "wexit"))
:= // Results in bad experession syntax on "wexit"
This would be the same old CCS limitation of "no pointers
to constant strings". Here's the function stricmp from
the string.h file:
signed int stricmp(char *s1, char *s2)
It's expecting pointers to the strings. But, you can't pass
a pointer to a constant string in CCS. You have to copy it
to ram first, with strcpy.
:=
:=I am using get_string(...) to capture a 6 byte string. I then need to compare the string to available commands.
:= pseudo... if (w_cmd==some_cmd) then...
:=
:=I can do this:
:= char wexit[6]="wexit";
:= ...
:= if (!stricmp(w_cmd, wexit))...
:=
:= but this method could tie up 100's of bytes of RAM.
:=
:=I am using CCS PCH v3.158 for a 18F6720.
:=
:=
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514856 |
|
|
eugeneb Guest
|
Re: stricmp() |
Posted: Thu May 29, 2003 3:52 pm |
|
|
The following is a solution received from CCS Support:
Because the PIC has separate RAM and ROM address spaces and the opcodes can not access the ROM space. The following is a better explination:
For data there is no way to know if a pointer is to RAM or to ROM becuase of the dual address space in the PIC and the inability to access ROM in most PICs. For example STRCMP could not know if the pointer being passed to it were RAM or ROM. You can pass an index into a constant array instead of the pointer however. For example:
char const keywords[21] = {"UP DOWN LEFT RIGHT"};
You can do:
int compare(char * cmd, byte index) {
int i;
for(i=0;i<5;i++,cmd++)
if(*cmd!=keywords[index+i])
return(FALSE);
return(TRUE);
}
int find_match(char * cmd) {
int i;
for(i=0;i<4;i++)
if(compare(cmd,i*5))
return(i+1);
return(0);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514870 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|