How to make a graphics.h program in C?
Hello,
I am trying to create a multiple bouncing balls program in C which will interact with each other. I managed to make it for one ball, but when I try to make it for more, it crushes. However, I can't understand where the problem is, as I use this library for the first time and I don't have a lot of experience. Can someone help me please?
Thank you in advance.
Here is my code:
#include
#include
#include
#include
#include
struct data
{
int c, m;
double x, y, r, sx, sy;
};
int main()
{
FILE *input;
int n, i, *num;
if((input=fopen("input.txt", "r"))!=NULL)
{
fscanf(input, "%d", &n);
num=(int *)malloc(n*sizeof(struct data));
if(num!=NULL)
{
struct data ball[n];
for(i=0; i= 0.03)
{
previous = finish;
setfillstyle(SOLID_FILL,BLACK);
setcolor(BLACK);
fillellipse(ball[i].x,ball[i].y,ball[i].r,ball[i].r);
ball[i].x+= ball[i].sx*step;
ball[i].y+= ball[i].sy*step;
if (ball[i].x+ball[i].r>=getmaxx() || ball[i].x-ball[i].r=getmaxy() || ball[i].y-ball[i].r