Recursive problem

From: Andy (anaylor_at_nc.rr.com)
Date: 01/25/04


Date: 25 Jan 2004 09:25:36 -0800

Working on Recursion in a CSC class.

The object is to create a recursive string length function w/o using
strlen.

I'm having problems with my code causing a segmentation fault. It
looks as if it's not returning 0 in the base case.

Function Code:

int recursivestringlength(const char buffer[]){
   if (buffer=='\0')
   return 0;
      else
      return(1+recursivestringlength(buffer+1));

Function Call:
    const char s[80]="";
    int job = recursivestringlength(&s[1]);

Any ideas?

Thanks,
Andy...



Relevant Pages

  • Re: Recursive problem
    ... > Working on Recursion in a CSC class. ... > The object is to create a recursive string length function w/o using ... > I'm having problems with my code causing a segmentation fault. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Recursive problem
    ... > The object is to create a recursive string length function w/o using ... > I'm having problems with my code causing a segmentation fault. ... there if we overlook "buffer" - no pointers at all. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Recursive problem
    ... > The object is to create a recursive string length function w/o using ... > I'm having problems with my code causing a segmentation fault. ...
    (alt.comp.lang.learn.c-cpp)