|
|
View previous topic :: View next topic |
Author |
Message |
BlueTower
Joined: 23 Oct 2008 Posts: 29
|
Passing a string to a buffer error? |
Posted: Thu Nov 27, 2008 4:39 am |
|
|
Hi all. I have the following function:
Quote: |
void Serial_RD(void)
{
#asm //Copy the Serial Number from the EEPROM Buffer (var_table)
MOVF var_table+2, 0 //High value (var_table[2])
MOVWF convInt24
MOVF var_table+3, 0 //Mid value (var_table[3])
MOVWF convInt24+1
MOVF var_table+4, 0 //Low value (var_table[4])
MOVWF convInt24+2
#endasm
CV_Int24ToStr(); //Convert to string (returns in convString)
cfgStringBuf = "#RI="; //Build the Output String
for (i = 0; i < 8; i++)
cfgStringBuf[i + 4] = convString[i];
cfgStringBuf[12] = 13;
CFG_WriteData(); //Write out via RS-232
}
|
and cfgStringBuf is declared as :
Quote: |
unsigned char cfgStringBuf [20]; //String Buffer
|
I got Error 49:'Expecting LVALUE such as a variable name or * expression' in line cfgStringBuf = "#RI=";
Any ideas why?
Regards |
|
|
Ttelmah Guest
|
|
Posted: Thu Nov 27, 2008 5:18 am |
|
|
strcpy(cfgStringBuf,"#RI=");
Two 'parts' to this. The first is 'standard C'. A string, is not a 'type', but an array of characters. Initialising with a string, involves moving the whole array. C allows this for the declaration of a variable, but not 'inline' as you show. However most 'latter variants' (C++ etc.), allow an inline initialisation like this. Unfortunately on the PIC, there is a problem. Because the 'constant' data is stored as part of the program memory space, and not as part of the RAM, you can't construct a pointer to the RAM, to perform the initialisation. Strcpy, has an 'overloaded' version of itself, that accepts a constant, and performs the data movement required.
Best Wishes |
|
|
BlueTower
Joined: 23 Oct 2008 Posts: 29
|
|
Posted: Thu Nov 27, 2008 7:24 am |
|
|
Thanks for quick reply. I am now facing the following problem:
I want to convert a 32-bit unsigned integer to a string.
I haven't found a suitable function in stdlib.h file. Any ideas ? |
|
|
Ttelmah Guest
|
|
Posted: Thu Nov 27, 2008 10:10 am |
|
|
sprintf
Basically you 'print' the variable to a string.
Best Wishes |
|
|
|
|
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
|