how to draw a line in c program given the slope and intercept of the line

Recommended Answers

All 6 Replies

Using which library? Or if that's part of the question: for which operating system?

Step back a bit.

C is a general purpose programming language. It specifies almost nothing about your hardware. C is used to program dishwashers and hard drive controllers and DVD players and telephones. C does not know what a keyboard is, or a monitor, or colours, or sounds. None of that is required by the C language.

This means that everything involving graphics relies on someone having written extra software to work with your hardware. If you have a sound device on your hardware, for example, someone must write the software for it and that software will not be part of your C compiler. Sometimes, your operating system will provide that software for you, in which case you won't have to install it but you will still have to learn how to use it. Sometimes, you will have to go looking for that software yourself, install it and then learn how to use it.

So, firstly, examine your operating system and see if it provides any functions and libraries for you to generate sound. If not, you will have to find some on the web, download it, install it, and learn how to use it. Because displaying graphics is sometihg your OS can already do (unless you're reading this over a teletype) it does already have libraries you can use. They may be easy. They may be horrifically difficult.

C is a very, very general purpose programming language and all that sort of thing is provided by additional software written specifically for your hardware. Long story short - there is no way within the C language definition and you have to work a bit harder for it.

A long time ago, in the days of DOS, some C compilers used to come with simple libraries to draw lines. If you're using one of those ancient C compilers, don't be tempted to use the graphics library it came with. Throw it all away and get something made in the last twenty years.

ok..i am using windows 7 os and am currently trying to draw the y=mx+c graph using 'graphics.h'...

can you please direct me with regards to the libraries that might be needed to generate the graphics....

graphics.h was a header file that came with Borland /Turbo C about twenty years ago. It's meant to be used in DOS. Twenty years ago.

Do you want to make an image file, or do you want to put a box on the screen and change the values of the pixels in that box?

You could do this with a low level library SDL and SDL_draw or SDL_gfx.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.