View previous topic :: View next topic |
Author |
Message |
No_Fear Guest
|
What is wrong with this code? |
Posted: Sun Jan 26, 2003 4:49 pm |
|
|
Hi There,
Sometime ago i asked here how to convert hex values to int values.Thanks to PCM_Programmer replied my question and sent me a piece of code.I copied this code and pasted then i compiled it with Ide Vers 3.20 and PCM v3.112, but it gives "Expecting LVALUE such as a variable name or * expression" on line includes "c = *ptr++;".What is wrong with this code? I can compile this piece of code with borland c++ builder v4.0 without any problem!! Can you advice me please?
Thanks.
char Hex2Int(char ptr[2])
{
char i, c, value;
value = 0;
for(i = 0; i < 2; i++) // Convert a maximum of 2 digits
{
c = *ptr++; // Get the char *** This Probl. Line ***
if(c >= 'a') // If char is lower case,
c &= 0x5f; // convert to upper case.
if(c < '0') // Check if the char is an ascii hex char
break;
if(c > 'F')
break;
if(c < 'A')
{
if(c > '9')
break;
} c -= 0x30; // Convert the char to binary
if(c > 9)
c -= 7;
value <<= 4; // Shift existing value left 1 nybble
value |= c; // Then combine it with new nybble
}
return(value);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 11013 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: What is wrong with this code? |
Posted: Sun Jan 26, 2003 5:42 pm |
|
|
I copied this code and pasted then i compiled it with Ide Vers 3.20 and PCM v3.112, but it gives "Expecting LVALUE such as a variable name or * expression" on line includes "c = *ptr++;".What is wrong with this code? I can compile this piece of code with borland c++ builder v4.0 without any problem!! Can you advice me please?
:=
:=char Hex2Int(char ptr[2])
---------------------------------------------------------
Change the line above to become this:
char Hex2Int(char *ptr)
If you're using Function Prototypes, make sure you
also change it there.
___________________________
This message was ported from CCS's old forum
Original Post ID: 11016 |
|
|
No_Fear Guest
|
Re: What is wrong with this code? |
Posted: Mon Jan 27, 2003 11:29 am |
|
|
Thank you! It compiles now.
:=I copied this code and pasted then i compiled it with Ide Vers 3.20 and PCM v3.112, but it gives "Expecting LVALUE such as a variable name or * expression" on line includes "c = *ptr++;".What is wrong with this code? I can compile this piece of code with borland c++ builder v4.0 without any problem!! Can you advice me please?
:=:=
:=:=char Hex2Int(char ptr[2])
:=---------------------------------------------------------
:=Change the line above to become this:
:=
:=char Hex2Int(char *ptr)
:=
:=If you're using Function Prototypes, make sure you
:=also change it there.
___________________________
This message was ported from CCS's old forum
Original Post ID: 11041 |
|
|
|