Multiple files

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Sep 2006
Posts: 327
Reputation: Colin Mac is on a distinguished road 
Solved Threads: 22
Colin Mac Colin Mac is offline Offline
Posting Whiz

Multiple files

 
0
  #1
Sep 12th, 2007
I have this C program with multiple files and I want to introduce a new file called enemy.c.
and I'm wondering if I'm going about this right.

game.h
  1. #ifndef GAME_
  2. #define GAME_
  3.  
  4. extern void game (void);
  5. extern void enemyFunc (void);
  6. extern int enemyPosX;
  7.  
  8. #endif
main.c
  1. int main (void)
  2. {
  3. game();
  4. }
game.c
  1. #include "game.h"
  2.  
  3. int enemyPosX = 452;
  4.  
  5. void game (void)
  6. {
  7. enemyFunc();
  8. }
enemy.c
  1. #include "game.h"
  2.  
  3. void enemyFunc (void)
  4. {
  5. enemyPosX -= 4;
  6. }
The program works but I'm wondering if I should make a new file called enemy.h
and put

extern void enemyFunc (void);
in it instead of in game.h, to have a header defining each .c file?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,868
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Multiple files

 
0
  #2
Sep 12th, 2007
>The program works but I'm wondering if I should make a new file called enemy.h
You can if you'd like. I don't see any benefit for it at this point though.
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 327
Reputation: Colin Mac is on a distinguished road 
Solved Threads: 22
Colin Mac Colin Mac is offline Offline
Posting Whiz

Re: Multiple files

 
0
  #3
Sep 12th, 2007
If I were to do it, I would need to include "game.h" in enemy.c as well seeing as I'm using the variable enemyPosX from it?
Last edited by Colin Mac; Sep 12th, 2007 at 5:22 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,868
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Multiple files

 
0
  #4
Sep 12th, 2007
>If I were to do it, I would need to include "game.h" in enemy.c
>as well seeing as I'm using the variable enemyPosX from it?
I would move everything that pertains to enemies into enemy.h. Then you would need to include enemy.h in game.c, which is a smidge more intuitive.
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 327
Reputation: Colin Mac is on a distinguished road 
Solved Threads: 22
Colin Mac Colin Mac is offline Offline
Posting Whiz

Re: Multiple files

 
0
  #5
Sep 12th, 2007
Thanks for your help.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 2105 | Replies: 4
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC