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 into a function

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



Joined: 25 Jan 2011
Posts: 12

View user's profile Send private message

Passing a string into a function
PostPosted: Fri Feb 04, 2011 9:52 am     Reply with quote

I was to do something like this.

Code:
foo( "This is a string" );

void foo( const char *string ) {
int x;
for( x = 0; string[x] != '\0'; x++ )
  print_char( string[x] );
}


Now most of this code is just for clarification this is not what I am actually attempting to do. I want to pass a string without having to declare it first with something like. string = "This is a string"; and then call foo( string );

I want to be able to pass a string using only one line of code. Secondly, I want to be able to step through the string one character at a time.

I know I can do something like this
Code:
void foo( char string ) { // code }

Although the problem with that is it calls that function for each individual character and doesn't include the terminating character '\0'.

Any ideas?
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Fri Feb 04, 2011 10:23 am     Reply with quote

Look at the thread immediately in front of this one 'Passing a const 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