Thread: how do I fix this

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    28

    how do I fix this

    when i execute this program i get a segmentation fault and i dont know wha tthat is can some one tell me what i did wrong
    Code:
    include<stdio.h>
    #include<math.h>
    
    
    
    main()
    {
            int door[101];
            int i,j;
            i=1;
                    for(i=1;1<=100;i++)
                    door[i]=0;
    
            for(i=1;1<=100;i++)
                    for(j=i;j<=100;j+=i)
                            door[j]=!door[j];
    
            for(i;i<=100;i++)
                    if(door[i])
                    printf("i");
    }

  2. #2
    abyss - deep C
    Join Date
    Oct 2007
    Posts
    46
    you are comparing two literals in the statement which is true forever...
    Code:
    for(i=1;1<=100;i++)
    you need to change it to
    Code:
    for(i=1;i<=100;i++)
    cheers
    maverix

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    28

    new problem

    ok after i fixed that i wanted it to print a list of 0 and 1 so that it would show what doors are open and which are closed. how would i do that.

  4. #4
    abyss - deep C
    Join Date
    Oct 2007
    Posts
    46
    this would do...
    Code:
    for(i=1;i<=100;i++)
        printf("door %d - %d\n", i, door[i]);
    maverix

  5. #5
    Registered User
    Join Date
    Feb 2008
    Posts
    28
    i tried it but it still gives me nothing

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I suggest that you try:
    Code:
    #include<stdio.h>
    
    int main()
    {
        int door[101] = {0};
        int i;
    
        for (i = 1; i < 101; i++)
        {
            printf("Door #&#37;d: %d\n", i, door[i]);
        }
    
        return 0;
    }
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. compiling my code, i can't fix error
    By howru in forum C Programming
    Replies: 2
    Last Post: 04-22-2008, 03:38 AM
  3. Drag and Drop code (please help me fix)
    By John_L in forum C# Programming
    Replies: 1
    Last Post: 11-17-2007, 06:11 PM
  4. C++ code need help to fix
    By McReal in forum C++ Programming
    Replies: 9
    Last Post: 05-12-2007, 02:48 PM
  5. Help me fix my mess!!!!
    By Starr in forum C++ Programming
    Replies: 35
    Last Post: 02-01-2006, 03:40 PM