Declare universal

This is a discussion on Declare universal within the C Programming forums, part of the General Programming Boards category; In this program, In the main function, the user inputs the values of certain variables, and then goes to a ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Location
    Barbados
    Posts
    31

    Declare universal

    In this program,
    In the main function, the user inputs the values of certain variables, and then goes to a menu, which is connected to various other functions.
    My problem is that I need the other functions to be able to use the variables declared in main.
    I don;t want to have to stick everything in one big function, that would be...difficult to find any errors in it.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    I might choose to package those variables in a struct and pass a pointer to this struct as a parameter to relevant functions.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    34
    can you give an example
    or be a little bit clearer

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Yes. Can you post the code you've written?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Aug 2007
    Location
    Barbados
    Posts
    31
    I don't know about posting the code I have written so far, It is really repetitive, and boring, not to mention long.
    But I can explain better.
    I am using the example from the FAQ for using the directional keys in a console program.
    But to make it a bit more protable, I have it asking for each arrow key to be pressed, and the resulting value is saved into a corresponding int declared in the main function(this all happens at the very beginning by the way) Now, I am trying to improve the Final Fantasy game I had originally made, by making the menus navigateable(is that a word?) with the directional keys, however, there is a menu in every function, and I do not want to have to ask for each key to be pressed every time it goes into another function!
    I'm thinking of the other things I had tried before, making a header file with ALL the declarations and Defines in it, it seemed to work well, but I can not have too much functions this way, and I want to know of another way to do it.
    So, basically, I already can get it done with the header file, but want to know of more ways.
    OR, even better, tell me why I can not have too much functions, my compiler gives me the error "Parameter initialized" I do not see anything wrong with that, but perhaps someone will know.
    Let me know if you want it explained more.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Programmatically declare vectors
    By franse in forum C++ Programming
    Replies: 15
    Last Post: 11-10-2008, 02:17 PM
  2. How to declare this function...
    By sreeramu in forum C Programming
    Replies: 6
    Last Post: 03-25-2008, 11:23 AM
  3. How to declare a list in another list???
    By zaracattle in forum C++ Programming
    Replies: 1
    Last Post: 10-24-2006, 08:24 AM
  4. Declare a template class as a friend?
    By AH_Tze in forum C++ Programming
    Replies: 11
    Last Post: 05-19-2004, 09:24 PM
  5. declare consts~
    By black in forum C++ Programming
    Replies: 2
    Last Post: 06-02-2002, 10:55 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21