c without usin any graphics function

S

shaanxxx

if u give cordinates to programme at run time and want a line to be
drawn.. how to do this in c without usin any graphics function?
like x1,y1 and x2,y2
and lines should be drawn from the 1st co-ordinate to 2nd one

any pointer would be appreciated

Thanks
 
R

Richard Heathfield

shaanxxx said:
if u give cordinates to programme at run time and want a line to be
drawn.. how to do this in c without usin any graphics function?
like x1,y1 and x2,y2
and lines should be drawn from the 1st co-ordinate to 2nd one

Use putchar.
any pointer would be appreciated

putchar is a pointer (except in cases where it's a macro).
 
T

Thad Smith

shaanxxx said:
if u give cordinates to programme at run time and want a line to be
drawn.. how to do this in c without usin any graphics function?

Drawing a line is a graphics function. You can either get one for your
target system or write your own, but in either case you would be using a
graphics function.
 
B

borkhuis

if u give cordinates to programme at run time and want a line to be
drawn.. how to do this in c without usin any graphics function?
like x1,y1 and x2,y2
and lines should be drawn from the 1st co-ordinate to 2nd one

any pointer would be appreciated

Thanks

#define GIVEN_COORDINATE1_X 1
#define GIVEN_COORDINATE1_Y 1
#define GIVEN_COORDINATE2_X 2
#define GIVEN_COORDINATE2_Y 2

int main(int argc, char *argv[])
{
printf("Take pencil and draw line from (%d,%d) to (%d,%d).\n",
GIVEN_COORDINATE1_X, GIVEN_COORDINATE1_Y,
GIVEN_COORDINATE2_X, GIVEN_COORDINATE2_Y);
}

And for pointers you can take a look here:
http://en.wikipedia.org/wiki/Pointer_(dog_breed)

Or you could try to do your own homework.
 
A

Alexei A. Frounze

if u give cordinates to programme at run time and want a line to be
drawn.. how to do this in c without usin any graphics function?
like x1,y1 and x2,y2
and lines should be drawn from the 1st co-ordinate to 2nd one

any pointer would be appreciated

Thanks

Most portable ways, not requiring graphics libraries:
1. Draw the line using printf(), assuming 1 character = 1 pixel. You
can save this to a text file.
2. Draw the line in a memory buffer and then save it to a graphics
file that you can view using a web browser or graphics editor/viewer.
Formats that are easy to implement: BMP, XBM (http://en.wikipedia.org/
wiki/XBM :), PCX, etc.

Alex
 
G

Gordon Burditt

if u give cordinates to programme at run time and want a line to be
Drawing a line is a graphics function. You can either get one for your
target system or write your own, but in either case you would be using a
graphics function.

Does "ASCII art" qualify as drawing a line? ( ---------- or _________
or you can use "character pixels" where every character position on a
(large) piece of paper is, say, @ or space). At least it doesn't
require graphics hardware.

Is "ASCII art" a graphics function?
 
M

Mark McIntyre

Drawing a line is a graphics function.

Whats wrong with
puts("_______");
puts("|");
puts("|");
puts("|");

?
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
O

osmium

Mark McIntyre said:
Whats wrong with
puts("_______");
puts("|");
puts("|");
puts("|");

It doesn't meet the spec. The OP gave x and y coordinates in his question.
Rounding an angle to the nearest 45 degrees, at best, wouldn't satisfy that
by any stretch of the imagination.
 
W

Walter Roberson

"Mark McIntyre" writes:
It doesn't meet the spec. The OP gave x and y coordinates in his question.
Rounding an angle to the nearest 45 degrees, at best, wouldn't satisfy that
by any stretch of the imagination.

The OP did not require that the drawn line proceed straight from
the beginning to ending coordinates. If the coordinates are
integral and finite, then you could draw a 45 degree line of length
min(abs(x1-x0),abs(y1-y0)), and a straight line of length
max(abs(x1-x0),abs(y1-y0))-min(abs(x1-x0),abs(y1-y0))
provided that the shorter of these two fit whatever page-size is in use.
 
U

user923005

if u give cordinates to programme at run time and want a line to be
drawn.. how to do this in c without usin any graphics function?
like x1,y1 and x2,y2
and lines should be drawn from the 1st co-ordinate to 2nd one

It's fairly difficult to draw a line. They are infinitely long.
Segments are a bit easier.

1. Ask for rows and columns available on the terminal
2. Create an array of [rows][columns] characters
3. Draw a segment through your grid with something like this:
http://pubpages.unh.edu/~cs770/notes/lines.html
 
G

georgerxz

if u give cordinates to programme at run time and want a line to be
drawn.. how to do this in c without usin any graphics function?
like x1,y1 and x2,y2
and lines should be drawn from the 1st co-ordinate to 2nd one

any pointer would be appreciated

Thanks

#include<stdio.h>
#include<conio.h>

void main()
{
int b=176;
textcolor(8); // Use this inbuilt function in C to change the color
of text
textbackground(123); /* use this inbuilt function to change the color
of background screen just change the argument passed to the function
color of screen will change depending upon the graphics card installed
and monitors color support */

for(b=176;b<224;b++)
{
printf("\n\t %c",b);
}

/* Above for loop will print the characters available in C for
graphics programming
you can use these characters to design GUI (graphical user interface)
for your application.
Even The turboc Editor can be designed with the above characters. Just
you have to use the for
and while loop properly */


getch();

}


For More C Source Codes and tutorials refer
http://zsoftwares.googlepages.com/CPrograms.html
 
K

Keith Thompson

#include<stdio.h>
#include<conio.h>

This header is non-standard.
void main()

Wrong. main returns int.
{
int b=176;
textcolor(8); // Use this inbuilt function in C to change the color
of text

There is no 'textcolor' function in standard C.
textbackground(123); /* use this inbuilt function to change the color
of background screen just change the argument passed to the function
color of screen will change depending upon the graphics card installed
and monitors color support */

There is no 'textbackground' function in standard C.
for(b=176;b<224;b++)
{
printf("\n\t %c",b);
}

/* Above for loop will print the characters available in C for
graphics programming
you can use these characters to design GUI (graphical user interface)
for your application.
Even The turboc Editor can be designed with the above characters. Just
you have to use the for
and while loop properly */

This is entirely system-specific.

There is no 'getch' function in standard C.
}


For More C Source Codes and tutorials refer
http://zsoftwares.googlepages.com/CPrograms.html

How many times do you intend to advertise this site? Once was more
than enough.
 
W

Willem

shaanxxx wrote:
) if u give cordinates to programme at run time and want a line to be
) drawn.. how to do this in c without usin any graphics function?
) like x1,y1 and x2,y2
) and lines should be drawn from the 1st co-ordinate to 2nd one
)
) any pointer would be appreciated

What do you want the line to be drawn on ? Be very specific.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 
C

Chris Hills

Keith Thompson said:
This header is non-standard.

A more useful comment is that this only works on and MS platform?
Wrong. main returns int.

Not always but if we are assuming "conio.h" then it should
There is no 'textcolor' function in standard C.

He is apparently using an MS platform. If you can't tell that perhaps
you should not be giving any advice.
This is entirely system-specific.

So what?

To quote PJP in May 2006
//////////////////////////////////
* People who know the value of writing portable code know to follow
standards. Those who don't simply don't, and mostly don't care, and
mostly benefit from using the nonstandard extensions. So what's the big
deal?
////////////////////////////
How many times do you intend to advertise this site? Once was more
than enough.

Et too... No need to keep up the "this is not standard C" mantra Either
be helpful or don't get involved.
 
R

Richard Bos

Chris Hills said:
A more useful comment is that this only works on and MS platform?

_Some_ M$ platforms.
He is apparently using an MS platform. If you can't tell that perhaps
you should not be giving any advice.

Or perhaps Mr. georgerzx should not be using terms like "inbuilt
function in C".
Et too... No need to keep up the "this is not standard C" mantra Either
be helpful or don't get involved.

Pointing out that code given out may well not work on the OP's platform
is very helpful.

Richard
 
R

Richard Heathfield

Chris Hills said:
A more useful comment is that this only works on and MS platform?

Nothing in the rules says that <conio.h> can't be used for any purpose
on any platform. It's perfectly legal to release a library on a
Microsoft platform (or on any other platform) that publishes its
no matter what functionality said:
Not always but if we are assuming "conio.h" then it should

Whether main may return something other than int does *not* depend on
but on said:
He is apparently using an MS platform. If you can't tell that perhaps
you should not be giving any advice.

I agree that it is likely that he's using Turbo C under MS-DOS or
MS-Windows, but the C Standard does not guarantee this.

<snip>
 
C

Chris Hills

Richard Heathfield said:
Chris Hills said:
ise.


Whether main may return something other than int does *not* depend on
the availability or otherwise of a header named <conio.h>, but on
whether the implementation is a hosted C90 implementation.

A hosted C90 platform... however if he is using conio I think it is
fairly safe to assume he is on an MS platform so it should return an Int
I agree that it is likely that he's using Turbo C under MS-DOS or
MS-Windows, but the C Standard does not guarantee this.

The C standard is not relevant at this point. What is relevant that he
constructs a good program using C with the extensions available for his
platform. Portability is a non issue here.
 
P

Philip Potter

Richard said:
Chris Hills said:


Whether main may return something other than int does *not* depend on
the availability or otherwise of a header named <conio.h>, but on
whether the implementation is a hosted C90 implementation.

Even on a freestanding implementation main may be required to return int.

Are hosted implementations free to accept void main(void) if they wish?
Obviously they must still accept int main(void).
 
R

Richard Heathfield

Chris Hills said:
A hosted C90 platform...

The C Standard doesn't define, or even use, the term "platform", so we
can't guarantee that we are using the word in the same way.
however if he is using conio I think it is
fairly safe to assume he is on an MS platform so it should return an
Int

int (C doesn't define the term "Int"). In my previous reply I pointed
out why your assumption is not necessarily correct.
The C standard is not relevant at this point.

If that is the case, then he would be better off seeking advice in a
newsgroup dedicated to discussing his implementation.

<snip>
 
R

Richard Heathfield

Philip Potter said:
Even on a freestanding implementation main may be required to return
int.

Very true. Nevertheless, whether it *may* (i.e. is allowed to) return
something other than int (and still remain a correct program) depends
on the criteria I gave.
Are hosted implementations free to accept void main(void) if they
wish?

Yes. Implementations, hosted or otherwise, have always been free to
provide extensions which do not break correct programs. Furthermore,
they have always been free to accept incorrect programs.
Obviously they must still accept int main(void).

Indeed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top