Thread: How can i draw a line?

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    230

    How can i draw a line?

    What am i missing?
    Code:
    #include <stdio.h>
    #include <graphics.h>
    
    int main(void){
    	InitGraphics(0.5, 0.5);
    	Drawline(0.0, 1.0);
    return 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Without you telling us which OS / Compiler / graphics library you're using - who the hell knows.

    I mean, you didn't even post any error messages.
    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
    Registered User
    Join Date
    Feb 2009
    Posts
    68
    Grab a pen & paper, put the pen in your hand, make sure the tip is exposed & start moving the tip of the pen on the paper.

  4. #4
    Registered User Char*Pntr's Avatar
    Join Date
    Sep 2007
    Location
    Lathrop, CA
    Posts
    198
    Quote Originally Posted by madmax2006 View Post
    Grab a pen & paper, put the pen in your hand, make sure the tip is exposed & start moving the tip of the pen on the paper.
    You forgot 2 important steps:

    1) get out of bed in the morning...

    2) turn off the computer...

    Then start using the the pencil and paper.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Brack, you should be able to get to help on this, by putting your cursor on the word (maybe Drawline() here), and pressing a key combination: f1,and ctrl+f1 are popular choices.

    This is how it's done in Turbo C, and some info.
    Code:
     /*
     line   Draws a line between two specified points.
    
     Syntax:
       void far line(int x1, int y1, int x2, int y2);
    
     Prototype in:
     graphics.h
    
     Remarks:
    Draws a line from (x1,y1) to (x2,y2) using the current color, line style,
    and thickness. It does not update the current position (CP).
    
     Return Value: None.
    
     Portability:
    This function is unique to Turbo C++.
    
    It works only with IBM PCs and compatibles equipped with supported graphics
    display adapters.
    
     See Also:
      getlinesettings    lineto      setlinestyle
      linerel            setcolor    setwritemode
    
     Example:
     */
    
     #include <graphics.h>
     #include <stdlib.h>
     #include <stdio.h>
     #include <conio.h>
    
     int main(void)
     {
        /* request auto detection */
        int gdriver = DETECT, gmode, errorcode;
        int xmax, ymax;
    
        /* initialize graphics and local variables */
        initgraph(&gdriver, &gmode, "");
    
        /* read result of initialization */
        errorcode = graphresult();
        /* an error occurred */
        if (errorcode != grOk)
        {
           printf("Graphics error: %s\n", grapherrormsg(errorcode));
           printf("Press any key to halt:");
           getch();
           exit(1);
        }
    
        setcolor(getmaxcolor());
        xmax = getmaxx();
        ymax = getmaxy();
    
        /* draw a diagonal line */
        line(0, 0, xmax, ymax);
        /* draw a rectangle */
        line(70, 50, 300, 50);
        line(300, 50, 300, 150);
        line(300, 150, 70, 150);
        line(70, 150, 70, 50);
        /* clean up */
        getch();
        closegraph();
        return 0;
     }
    This works in Windows XP.

  6. #6
    Registered User
    Join Date
    Aug 2010
    Posts
    230
    Quote Originally Posted by Salem View Post
    Without you telling us which OS / Compiler / graphics library you're using - who the hell knows.

    I mean, you didn't even post any error messages.
    thank you salem...

    I did not knew that OS/Compiler needed...
    i use ubuntu 10.04 LTS. and my programs are written in gedit and compiled with the gcc/g++ command (in terminal).

    If there is anything else you want to know please let me know...
    oh, i don' t know which library i should use. Actually this is my problem...

    Grab a pen & paper, put the pen in your hand, make sure the tip is exposed & start moving the tip of the pen on the paper.
    Oh, so you can not write a program...only using paper eh? you probably have some more things to learn...

    Code:
    Quote:
    Originally Posted by madmax2006 View Post
    Grab a pen & paper, put the pen in your hand, make sure the tip is exposed & start moving the tip of the pen on the paper.
    You forgot 2 important steps:
    
    1) get out of bed in the morning...
    
    2) turn off the computer...
    
    Then start using the the pencil and paper.
    advice: grab a pc and start programing so as sometime you can draw in the screen...

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If I run package manager and type in "graphics", I get over 700 matches.

    Care to narrow it down a little?

    > oh, i don' t know which library i should use. Actually this is my problem...
    So what you're really saying is that you got "unable to find graphics.h include file" ?

    Like I said, there are many choices.
    But if you're a relative newbie, then perhaps libsdl (look for it in the package manager)
    Then visit Simple DirectMedia Layer
    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.

  8. #8
    Registered User
    Join Date
    Aug 2010
    Posts
    230
    thank you...i' ll check this out...

  9. #9
    Registered User
    Join Date
    Oct 2010
    Posts
    1
    #include <stdio.h>
    #include <graphics.h>

    int main(void){
    InitGraphics(0.5, 0.5);
    Drawline(0.0, 1.0);
    return 0;
    }


    I dont get any compile time error instead i get a run-time error saying
    "BGI error: Graphics not initialized (use initgraph)"
    Last edited by nellaikrishna; 10-20-2010 at 10:54 AM.

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You didn't load the graphics driver.

    See my info and program in this thread, post #5 for how to do it.

    and Welcome to the forum, Nellaikrishna!

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Another random hijack, with off-topic, unformatted code.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Clearing single line?
    By louieansonng in forum C Programming
    Replies: 14
    Last Post: 07-26-2009, 11:10 PM
  2. ASM beginner gets 24 compiler errors on hello world...
    By Desolation in forum Tech Board
    Replies: 12
    Last Post: 06-16-2007, 10:21 PM
  3. Replies: 19
    Last Post: 05-30-2007, 05:47 PM
  4. Move the Caret to a line
    By TheDan in forum Windows Programming
    Replies: 3
    Last Post: 08-07-2005, 12:59 PM
  5. Debugging link error
    By bubux in forum C Programming
    Replies: 5
    Last Post: 07-06-2002, 02:19 PM