Ok, I'm kind of confused. I swore I understood what I was doing a second ago. xD
I'm trying to learn C and failing apparently. My tutorial gave me this assignment:
Assignment: Write a program that repeatedly accepts user input and then prints the numbers between 0 and the entered number. If the user enters a number less than or equal to zero, the program will exit.
So, I thought that it would be easy enough. So I write some probably atrocious code.
Code:
#include <stdio.h>
int main(void){
int x, z = 0; //variables
scanf("%d",x); //user input
if(x>0){ //check user input
int y;
for(y=1;y<=x;y++){ //loop to add all integers between 0 and x together
z += y;
}
printf("%d\n",z); //print result
main(); //restart
}
return 0; //end
}
After compiling, I run and it gives me this:
20776 [main] a 2268 _cygtls::handle_exceptions: Error while dumping state (probably corrupted stack)
Segmentation fault (core dumped)
Now I really have no idea what I'm doing. Can anyone give me pointers? -.-;