Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

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


0 Answer
Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.