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
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
 

aProgrammer

Full Member level 2
Full Member level 2
Joined
Mar 29, 2001
Messages
148
Helped
23
Reputation
44
Reaction score
13
Trophy points
1,298
Location
Syldavia
Activity points
611
just try :

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

    siongboon

    Points: 2
    Helpful Answer Positive Rating

siongboon

Advanced Member level 1
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 aProgrammer,

It works. Thank you very much.

Best Regards,
Siong Boon
 

jhbbunch

Full Member level 4
Full Member level 4
Joined
Feb 21, 2006
Messages
197
Helped
17
Reputation
34
Reaction score
3
Trophy points
1,298
Activity points
2,902
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

siongboon

Advanced Member level 1
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
Thanks jhbbunch,

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

jhbbunch

Full Member level 4
Full Member level 4
Joined
Feb 21, 2006
Messages
197
Helped
17
Reputation
34
Reaction score
3
Trophy points
1,298
Activity points
2,902
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.
 

bhq

Member level 5
Member level 5
Joined
Jun 11, 2008
Messages
80
Helped
9
Reputation
18
Reaction score
2
Trophy points
1,288
Activity points
1,711
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

Top