title: Problems with calling functions that change the vals of structs
body: <p>If I call the functions that move the ball/find collisions, it doesn't work. But if I type down the contents of the function replacing "b" with "ball1", it does work. I have tried many, many, many things in order to fix it, but to no avail. I'm sorry the code is so long, but I'm afraid that if I just include a snippet, it won't be able to be fixed.</p>
  
  <p>code:</p>
  
  <pre><code>#include "SDL/SDL.h"
  #include "SDL/SDL_image.h"
  #include &lt;math.h&gt;
  #include &lt;stdbool.h&gt;
  
  #define SCREEN_WIDTH 500
  #define SCREEN_HEIGHT 500
  #define SCREEN_BPP 32
  #define GRAVITY 1
  
  SDL_Surface *image = NULL;
  SDL_Surface *screen = NULL;
  SDL_Event event;
  
  SDL_Surface *loadImage(char *filename) {
      SDL_Surface *optimizedImage = NULL;
      SDL_Surface *loadedImage = IMG_Load(filename);
      if (loadedImage != NULL) {
          optimizedImage = SDL_DisplayFormat(loadedImage); /*optimizes image*/
          SDL_FreeSurface(loadedImage);
      }
  
      return optimizedImage;
  }
  
  void applySurface(int x, int y, SDL_Surface *source, SDL_Surface *destination) {
      SDL_Rect offset;
      offset.x = x;
      offset.y = y;
  
      SDL_BlitSurface(source, NULL, destination, &amp;offset);
  }
  
  bool initSDL(void) {
      if (SDL_Init(SDL_INIT_EVERYTHING) == -1) {
          return NULL;
      }
      screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
  
      if (screen == NULL) {
          return NULL;
      }
  
      SDL_WM_SetCaption("Bounce", NULL);
      return true;
  }
  
  /*Cleans all needed things*/
  void cleanUp(SDL_Surface *image) {
      SDL_FreeSurface(image);
      SDL_Quit();
  }
  
  /*The Ball structure for OOP*/
  struct Ball {
      int x;
      int y;
      int vy;
      int vx;
      SDL_Surface *image;
  };
  
  /*initialize a Ball structure*/
  struct Ball ball_initBall(int x, int y, int vy, int vx, char *filename) {
      struct Ball b;
      b.x = x;
      b.y = y;
      b.vy = vy;
      b.vx = vx;
      b.image = loadImage(filename);
  
      return b;
  }
  
  void ball_move(struct Ball b) {
      b.x += b.vx;
      b.y += b.vy;
      b.vy += GRAVITY; 
  }
  
  void ball_wallCollide(struct Ball b) {
      if (b.x &lt;= 1 || b.x &gt;= 500 - 48) {
          b.vx *= -1;
      }
  
      if (b.y &lt;= 1 || b.y &gt;= 500 - 49) {
          b.vy *= -0.95;
      }
  }
  
  int main(int argc, char *argv[]) {
      bool running = true;
      initSDL();
  
      struct Ball ball1 = ball_initBall(SCREEN_HEIGHT/2, SCREEN_WIDTH/2, 1, 3, "resources/ball.jpg");
  
      while (running) {
          applySurface(ball1.x, ball1.y, ball1.image, screen);
  
  
          ball_move(ball1);
          ball_wallCollide(ball1);
  
          while (SDL_PollEvent(&amp;event)) {
              if (event.type == SDL_QUIT) {
                  running = false;
              }
          }
          SDL_Flip(screen);
          SDL_FillRect(screen, &amp;screen-&gt;clip_rect, SDL_MapRGB(screen-&gt;format, 0, 0, 0));
          SDL_Delay(50);
      }
      cleanUp(ball1.image);
      return 0;
  }
  </code></pre>