CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Passing a string to a buffer error?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
BlueTower



Joined: 23 Oct 2008
Posts: 29

View user's profile Send private message

Passing a string to a buffer error?
PostPosted: Thu Nov 27, 2008 4:39 am     Reply with quote

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







PostPosted: Thu Nov 27, 2008 5:18 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Nov 27, 2008 7:24 am     Reply with quote

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







PostPosted: Thu Nov 27, 2008 10:10 am     Reply with quote

sprintf

Basically you 'print' the variable to a string.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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