Thread: Beginner programming

  1. #1
    Confused easily.
    Join Date
    Feb 2005
    Posts
    2

    Question 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. 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
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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 &
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    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.
    If you understand what you're doing, you're not learning anything.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Code:
    while(ID != 0);
    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;
    }

  5. #5
    Confused easily.
    Join Date
    Feb 2005
    Posts
    2
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Same old beginner question...
    By Sharmz in forum C Programming
    Replies: 15
    Last Post: 08-04-2008, 11:48 AM
  2. What are some good beginner programs I shouold make?
    By oobootsy1 in forum C# Programming
    Replies: 6
    Last Post: 08-09-2005, 02:02 PM
  3. Best Free Beginner Online Books/Tutorials?
    By Zeusbwr in forum C++ Programming
    Replies: 2
    Last Post: 10-12-2004, 05:52 PM
  4. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 11:21 AM