c - realloc from within a function -


I have a structure called ball, many balls, an array of balls and a function where I add a new ball Want to arrange:

straight:

  typingfuff straight ball {bitmap * image; Int x; Int y; Int vector_x; Int vector_y; } Ball;  

( non-functional function):

  void add_balls (int * num_balls, ball ** myballs) {num_balls ++ ; * Myball = Rehalok (* Meyball; * num_balls * sizeof (ball)); * Mikeball [* num_balls-1] - & gt; X = rand ()% 640; * Myball [* num_balls-1] - & gt; Y = rand ()% 480; * Myball [* num_balls-1] - & gt; Vector_x = rand ()% 10; * Myball [* num_balls-1] - & gt; Vector_yyy = rand ()% 10; * Myball [* num_balls-1] - & gt; Image = load_biltmap ("blue_ball.bmp", NULL); }  

and within the function call main:

  add_balls (& amp; num_balls, and myballs); The call fails in the following error messages:  
  pc: in function 'add_balls': pc: 19: error: invalid type argument' Unary * 'PC: 20: Error: Illegal type of' unary * 'Argument PC: 21: Error: Illegal type of' unary * 'Argument PC: 22: Error: Invalid type of' unary * 'Logic PC: 23: Error: Incomparable type of assignment  

Any help?

This helped get it compiled, but I get a segmentation fault error in runtime. This is the complete code, if it interests:

  #include & lt; Allegro.h & gt; # Include & lt; Stdlib.h & gt; # Include & lt; Time.h> # Include & lt; Math.h> # Defined NUM_BALLS 10 types of key structure ball {BITMAP * image; Int x; Int y; Int vector_x; Int vector_y; } Ball; Zero add_balls (int * num_balls, ball ** myballs) {num_balls ++; Myball = Rialok (* Myball, * Newsball * Size); Mayball [* num_balls-1] - & gt; X = rand ()% 640; Mayball [* num_balls-1] - & gt; Y = rand ()% 480; Mayball [* num_balls-1] - & gt; Vector_x = rand ()% 10; Mayball [* num_balls-1] - & gt; Vector_y = rand ()% 10; Mayball [* num_balls-1] - & gt; Image = load_biltmap ("blue_ball.bmp", NULL); } Int main () {allegro_init ()); Install_keyboard (); Srand (time (0)); Install_timer (); Set_color_depth (32); Set_gfx_mode (GFX_AUTODETECT_WINDOWED, 640,480,0,0); Bitmap * buffer = faucet; Buffer = create_biltmap (640,480); Ball Meyball; Myball = Mallow (NUM_BALLS * size); Int num_balls = NUM_BALLS; Bitmap * bg = faucet; Bg = load_bitmap ("bg.bmp", NULL); Int i; (I = 0; i & lt; num_balls; i ++) for (myballs [i] .x = rand ()% 640; Maybol [i]. I = Rand ()% 480; Maybol [i] .vector_x = rand ()% 10; Maybol [i]. Vector_y = rand ()% 10; Maybol [i] .image = load_bitmap ( "blue_ball.bmp", NULL);} Int bg_vector_x; float Biji_vector_wai; while (! key [ KEY_ESC]} {vsync (); (I = 0; i & lt; num_balls; i ++) {if (myball [ii]. X + microl [i]. Vector_x> 640 || myball [ii] .x + Myball [i]. Vector_x <0 {{Myball [ii] .vector_x * = -1;} If (Myball [I]. Eye + Myball [I] .Vector_A> 480+ Mayault [I] I + miles [i]. Vector_a <0) {mayob Scroll [I] .vector_y * = -1;} Maybol [i]. X + = Maybol [i] .vector_x; Maybol [i] Kai + = Maybol [i] Kvector_a;} if (keys [KEY_UP]) {Add_balls (& amp; num_balls, and myballs);} Clear_bitmap (buffer); int ii; (i = 0; i  

In your modified add_balls function, you increase the pointer num_balls, In you want to increase the contents of the pointer, (* num_balls) ++;


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -