Thread: problem with plot a linear graph on the command line

1. problem with plot a linear graph on the command line

Code:
```/*This program produce real numbers,x and y.
The minimum number for x is 1,... and the maximum
number is 14{...decimal places}because C is 15 spaces " "
The minimum number for y is 1,... and the maximum
number is 24 {...decimal places}because L is 25 spaces " "
C=WIDTH
L=HEIGHT
* * * * * * * * * * * * * * * *
*			      *
*			      *
*			      *
*			      *
*			      *
*			      *
*			      *
*	                      *
*			      *
*			      *
*			      *
*			      *
*			      *
*			      *
*			      *
*			      *
*			      *
*			      *
*			      *
*			      *
*			      *
*			      *
*                             *
*                             *
* * * * * * * * * * * * * * * *
^
|
(0,0)

*/
#include<stdio.h>
#define WIDTH 15
#define HEIGHT 25
int i;
double my_function(double x);
int main(void)
{
double x_spot,y_spot;
for(i=WIDTH-1;i>0;i--)
{
x_spot=(double)i/WIDTH;
y_spot=my_function(x_spot);
printf("%lf\t%lf\n",x_spot,y_spot);
}
return 0;
}
double my_function(double x)
{
double y;
y=x*x*x+x*x-x+0.2;
if (y>0 && y<HEIGHT)/*only possitive values*/
return y;
}```
--------------------------------------------------------------------------------

HOW I CAN PRINT THE GRAPH IN THE BOX?
first i run the secondary programm and i place x y values in a *.txt file
secondly i scanf the values and finally place for each coordinate one spot at the command line
i must convert x and y into integers first (int)x=x_spot*HEIGHT; (int)y=y_spot*WIDTH;
I dont understand how i could print the spot for each cordinate starting from the left down corner of
the rectangle (0,0)

2. Draw it in memory before you draw it on screen

Code:
`char paper[25][80];`
Start by filling this with spaces

Then do
paper[y][x] = '*';
at the points you want to plot

When you're done, just print the paper

3. explain

Draw it in memory before you draw it on screen

Code:
char paper[25][80];

Start by filling this with spaces

Then do
paper[y][x] = '*';
at the points you want to plot

My dimensions are 15*25..(what is 80 for?)

4. It's for you to read between the lines and apply it to your specific situation
If you can't change
char paper[25][80];
into
char paper[15][25];

5. Sorry

sorry !
I REALLY APRECIATE YOUR HELP SALEM
THANKS A LOT ):

6. Salem what is wrong?

Code:
```#include<stdio.h>
#define WIDTH 25
#define HEIGHT 15
int main(void)
{
char star='*',space=' ';
int y,x,c;
double y_spot,x_spot;
char my_graph[WIDTH][HEIGHT];
for(y=0;y<HEIGHT;y++)
{
for(x=0;x<WIDTH;x++)
{
my_graph[y][x]=star;
}
}
do{
c=scanf("%lf %lf\n",&y_spot,&x_spot);
y_spot*=HEIGHT;
x_spot*=WIDTH;
my_graph[(int)x_spot][(int)y_spot]=space;
}while(c!=EOF);

for(y=0;y<HEIGHT;y++)
{
for(x=0;x<WIDTH;x++)
{
printf("%c",my_graph[y][x]);
}
printf("\n");
}
return 0;
}```
0.933333 0.950815
0.866667 0.735407
0.800000 0.552000
0.733333 0.398815
0.666667 0.274074
0.600000 0.176000
0.533333 0.102815
0.466667 0.052741
0.400000 0.024000
0.333333 0.014815
0.266667 0.023407
0.200000 0.048000
0.133333 0.086815
0.066667 0.138074
The y x spots