-
Beginner programming
I'm trying to write a loop, but there are two major problems. The 0 sentinel never works, and after one time through, it says:
Segmentation Fault (core dumped)
I don't even know what that means. :confused: Please go easy on me b/c this a first for me.
Code:
printf("\n\nEnter ID, 0 to exit");
while(ID != 0);
scanf("%d",&ID);
{
blah
blah
blah
printf("\n\nEnter ID, 0 to exit");
scanf("%d", ID
}
-
Well post the code you actually tried.
The code you posted
- does not compile
- the ; at the end of the while is really, really bad.
Your 2nd scanf is missing an &
-
Please post your code in its entirety. That code won't even compile. One thing I do notice is that you have a semi-colon at the end of your while() statement which is probably not what you want.
-
Your code execution will never pass that line, because of the semicolon after the while declaration. The correct form of a while loop would look something like this:
Code:
int i = 0;
while(i < 10)
{
printf("i = %d\n",i);
i = i + 1;
}
-
Alright, thanks. I got rid of the semicolon , added the & at the end,and switched the while and scanf statements. Now it loops till I enter the 0. I really appreciate the help. And next time I'll try to post the whole code.
Thanks again.