Trying to learn c from a very simple book (c programming in easy steps) which is working ok for a duffer like me.
I have though stumbled across an issue not discussed in my simple book. The book goes through a short example of recursive functions.
The code below works up to a point, that point being somewhere between 100,000 and 1,000,000. Entering "1000000" gets a Segmentation fault at 737975
#include <stdio.h>
void count_down_from(int x);
int main()
{
int num;
printf("Enter a positive integer to count down from: ");
scanf("%d", &num);
count_down_from(num);
return 0;
}
void count_down_from(int x)
{
printf("%d\n",x);
--x;
if(x<0) return;
else count_down_from(x);
}
I have though stumbled across an issue not discussed in my simple book. The book goes through a short example of recursive functions.
The code below works up to a point, that point being somewhere between 100,000 and 1,000,000. Entering "1000000" gets a Segmentation fault at 737975
#include <stdio.h>
void count_down_from(int x);
int main()
{
int num;
printf("Enter a positive integer to count down from: ");
scanf("%d", &num);
count_down_from(num);
return 0;
}
void count_down_from(int x)
{
printf("%d\n",x);
--x;
if(x<0) return;
else count_down_from(x);
}