Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C programming, problem assigning string

Status
Not open for further replies.

siongboon

Advanced Member level 1
Joined
Jan 24, 2006
Messages
423
Helped
45
Reputation
88
Reaction score
10
Trophy points
1,298
Location
Singapore
Activity points
4,075
Hi everyone,

I have the following problem doing string assignment with C18 microchip compiler.

For example, I am able to assign this way

const rom unsigned char testing[]={"GMxxx"};

what appear in memory is G,M,x,x,x


When I do it in another way, the data in memory becomes

const rom unsigned char testing[]={"GMxxx",0x00};

what appear in memory is 0x0E, ...

I hope if someone can explain to me what's going on???


I hope to append 0x0D 0x0A to the end of the string...
Is there any way I can do it in C18 compiler.
I am thinking of doing the following but the data retrieved is not what I want.

const rom unsigned char testing[]={"GMxxx",0x0D,0x0A};


Any alternative?

Thank you so much.
Siong Boon
 

just try :

const rom unsigned char testing[]={"GMxxx\r\n"};
 

    siongboon

    Points: 2
    Helpful Answer Positive Rating
Hi aProgrammer,

It works. Thank you very much.

Best Regards,
Siong Boon
 

I don't see how char testing[] = ("Gmxx", 0xa, 0xd); would even compile. It won't on my compiler. You are giving it a 5 byte value with "Gmxx" when it expects a single byte. You can't mix up strings of chars with individual chars.


char testing[]={'G','m','x','x', 0xd, 0xa, '0'}; should also work
 

    siongboon

    Points: 2
    Helpful Answer Positive Rating
Thanks jhbbunch,

this is also the solution I am looking for, for non ascii char.
Thank you.
 

Thanks for the reply. I should note that I made a mistake in the code. The last value should be 0, not '0' (ascii 0). 0 of course is the string terminating character in C. ASCII 0 is a printable character.
 

For using strings please burn your data in in ROM than use strings in C programming
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top