By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,197 Members | 1,205 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,197 IT Pros & Developers. It's quick & easy.

Passing array of characters help

P: 2
GDay everyone,

I'm a newbie in C programming.
Please help me if you're interested in.

How can I pass an array of characters in function 1 to function 2 in C.

Thanks in advance.


eric
Sep 17 '06 #1
Share this Question
Share on Google+
5 Replies


100+
P: 293
D_C
Expand|Select|Wrap|Line Numbers
  1. void passArray(int array[]);
works for integers, so if all is right in this world, change int to char and it should work.
Sep 17 '06 #2

Banfa
Expert Mod 5K+
P: 8,916
Expand|Select|Wrap|Line Numbers
  1. void passArray(int array[]);
works for integers, so if all is right in this world, change int to char and it should work.
Produces code identical to

Expand|Select|Wrap|Line Numbers
  1. void passArray(int *array);
  2.  
In fact in both cases array is of type int *. Tehre are various arguments for and against each type of declaration.
Sep 17 '06 #3

P: 61
The guy is talking about the array of characters.

So the function prototype should be of

data_type function(char *, int);

Here the second argument will specify the total number of characters in the character array you passed.
Sep 18 '06 #4

Banfa
Expert Mod 5K+
P: 8,916
The guy is talking about the array of characters.

So the function prototype should be of

data_type function(char *, int);

Here the second argument will specify the total number of characters in the character array you passed.
Not necessarily, all the string functions take an array of characters but don't require the size because of the NULL terminator.

What you say may be true but you don't have enough information to say because he hasn't said what the contents of his array of characters will be.
Sep 18 '06 #5

P: 61
See Banfa the guy clearly mentioned that he is passing an array of characters. So it may or may not terminate with null character. But a string will definitely terminate with a null character. So in the first case it is required to know priorly how many characters are there in the array.
Sep 19 '06 #6

Post your reply

Sign in to post your reply or Sign up for a free account.