I am getting a Seg Fault; can anyone explain the problem??
I believe this simple program is to find the # of instances a letter s occurs in the string literal "system" (which is obviously 2 times).
I am reviewing some programs for my final and I am obviously missing something quite simple but darned if I see it right now.
Code:
#include <stdio.h>
int Example2(char ch, char *str)
{
int result, i;
if (str[0] == '\0')
result = 0;
else if
(ch == str[0])
result = 1+Example2(ch,&str[i]);
else
result = Example2(ch,&str[i]);
return result;
}
main()
{
char a = 's';
char message[20] = "system";
printf("returned from Example2: %d\n",
Example2(a,message));
return 0;
}