Thread: Segmentation Error

  1. #1
    Registered User
    Join Date
    Oct 2010
    Location
    The land of nod
    Posts
    32

    Segmentation Error

    Hello all!

    Back again this week with a brand new error (well for me at least anyways)

    The program below is meant to draw a rectangle using asterics, but we've been made to do it a pretty specific way. At the moment I'm getting a segmentation error but I have no idea why. Below is the code!

    Code:
    #include <stdio.h>
    #include <math.h>
    
    int main()
    {
            int width = 0;
            int height = 0;
    
            printf("Please enter a width and height seperated by a comma\n");
            scanf("%d,%d, &width, &height");
    
    
            while (width>0)
            {
                    printf("*");
                    width--;
            }
    }

  2. #2
    Registered User
    Join Date
    Oct 2010
    Location
    The land of nod
    Posts
    32
    ok so got round my segmentation error!

    Here's the new bit of code

    Code:
    #include <stdio.h>
    #include <math.h>
    
    int main(int argc, char *argv[])
    {
            int width = 0; 
            int height = 0;
    
            printf("Please enter a width and height seperated by a comma\n");
            scanf("%d,%d",&width,&height); 
    
    
            while (width>0)
            {
                    printf("*");
                    width--;
            }
    }

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    FWIW.... int main(void) would also work.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LDAP Query
    By Travoiz in forum C++ Programming
    Replies: 0
    Last Post: 08-13-2009, 02:58 PM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  4. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM