Help: Recursive String Length Function
From: Andy (anaylor_at_nc.rr.com)
Date: 01/25/04
- Next message: Chris Newton: "Re: [C++] Best Way to ++booleans?"
- Previous message: Graeme Prentice: "Re: What about the Adaptive Communication Environment?"
- Next in thread: Artie Gold: "Re: Help: Recursive String Length Function"
- Reply: Artie Gold: "Re: Help: Recursive String Length Function"
- Reply: Chris Newton: "Re: Help: Recursive String Length Function"
- Reply: Jack Klein: "Re: Help: Recursive String Length Function"
- Reply: Jerry Coffin: "Re: Help: Recursive String Length Function"
- Reply: David White: "Re: Recursive String Length Function"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 24 Jan 2004 18:01:07 -0800
Hi,
Problem is to write a recursive function w/out strlen() to determine
the length of a c-style string array.
Can't Use pointers. Only arrays.
Problem is when I run it, it generates a segmentation fault.
Debuggin I see it walk the array to \0 but then it doesn't come
back/return.
Is this a problem with the recursion or the way I'm calling the
function?
Any ideas would be helpful.
Here is the function:
// Arguments:
// buffer - a c-style string to recursively measure the length of
// Returns:
// int - the length of the string passed in
// Side effects:
// none
int recursivestringlength(const char buffer[]){
if (buffer=='\0')
return 0;
else
return(1+recursivestringlength(buffer+1));
}
Function Call:
char s[80]="hello";
int job = recursivestringlength(&s[1]);
Thanks,
Andy...
- Next message: Chris Newton: "Re: [C++] Best Way to ++booleans?"
- Previous message: Graeme Prentice: "Re: What about the Adaptive Communication Environment?"
- Next in thread: Artie Gold: "Re: Help: Recursive String Length Function"
- Reply: Artie Gold: "Re: Help: Recursive String Length Function"
- Reply: Chris Newton: "Re: Help: Recursive String Length Function"
- Reply: Jack Klein: "Re: Help: Recursive String Length Function"
- Reply: Jerry Coffin: "Re: Help: Recursive String Length Function"
- Reply: David White: "Re: Recursive String Length Function"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|