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

Strings

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



Joined: 31 Mar 2011
Posts: 51
Location: Mexico

View user's profile Send private message

Strings
PostPosted: Thu Mar 31, 2011 6:15 pm     Reply with quote

In PIC C, how can I use string type variables?
In c# I can define
string a;

.
.
.
a = "example";
.
.
.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 31, 2011 7:09 pm     Reply with quote

The short answer is, you have to declare an array to hold the string.

http://cplus.about.com/od/learningc/ss/strings.htm
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

Re: Strings
PostPosted: Thu Mar 31, 2011 9:28 pm     Reply with quote

rfjhh wrote:
In PIC C, how can I use string type variables?
In c# I can define
string a;

.
.
.
a = "example";
.
.
.


I would also strongly recommend getting "The C Programming Language" by Kernighan & Ritchie

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
eliasS



Joined: 22 Jun 2010
Posts: 1
Location: Culiacan,Mexico

View user's profile Send private message MSN Messenger

PostPosted: Thu May 05, 2011 11:35 am     Reply with quote

In the old C a string basically is an array of chars, if you want to declare a string variable you don't use string="dummy"; instead you use a char array and you can't initialize it like this char myString="dummy"; This will create an array of chars of 6 elements 'd' will be at this location myString[0] and 'y' in myString[5]
Ttelmah



Joined: 11 Mar 2010
Posts: 19569

View user's profile Send private message

PostPosted: Thu May 05, 2011 2:55 pm     Reply with quote

99% right. The 'y' is at myString[4]. myString[5] contains the 'null terminator' '\0' character.
This is the only thing 'special' about strings. In C, a string is 'a null terminated array of characters. So a 5 character string, needs 6 characters of storage, the extra one for the terminator character.
Remember also, that since a 'string' is not a type in C, it has to be explicitly copied, either 'character by character', by looping through the array, or by using the string functions (which do this for you).

Best Wishes
rfjhh



Joined: 31 Mar 2011
Posts: 51
Location: Mexico

View user's profile Send private message

Thanks
PostPosted: Thu May 05, 2011 7:12 pm     Reply with quote

I've got the answer... thank you
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