- Joined
- Nov 8, 2006
- Messages
- 1
- Reaction score
- 0
:rockon: Hi all,
As an exercise, I am trying to come up with a function to count the
length of a character string using recursion. I came up with this:
As a recursion pattern:
int count_len( const char s[ ] ){
if ( s == ‘\0’) {
return 0; // may return other things
} else {
return count_len ( input-1 ); // means a smaller input will be put in the
}
It came out with error :| after I formed the counting length of character program.
Therefore, how could I form another program which applies to count the length of character??
Suppose there is NO global variables in the function. But it is allowed to write another function containing other the formal parameters for length count aid.
As an exercise, I am trying to come up with a function to count the
length of a character string using recursion. I came up with this:
As a recursion pattern:
int count_len( const char s[ ] ){
if ( s == ‘\0’) {
return 0; // may return other things
} else {
return count_len ( input-1 ); // means a smaller input will be put in the
}
It came out with error :| after I formed the counting length of character program.
Therefore, how could I form another program which applies to count the length of character??
Suppose there is NO global variables in the function. But it is allowed to write another function containing other the formal parameters for length count aid.