Defining main function!

This is a discussion on Defining main function! within the C++ Programming forums, part of the General Programming Boards category; hi ppl... i'm using Borland C++ 6 and when i started working i never made a main function since i ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    124

    Exclamation Defining main function!

    hi ppl...

    i'm using Borland C++ 6 and when i started working i never made a main function since i was using forms to test and run my program (using buttons on a form)...

    now i realized that i will need to have main cause i need to pass the input file as an argument to it...when i made main in the program, whatever i put in it is not activated when i run the code unless i press the buttons again! even if i put the methods which are activated by clicking a button in main...

    what could be the problem...

    my program structure is simple...

    Code:
    Astar class
    {
    
       - Node class
        {
    
        }
    
        - many functions 
    
    }
    
    - many functions
    //this is where i'm trying to use int main....
    what could be the problem...

    Thanks...

    Farooq
    Last edited by alvifarooq; 09-18-2004 at 05:03 PM.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    126
    Quote Originally Posted by alvifarooq
    now i realized that i will need to have main cause i need to pass the input file as an argument to it...
    You shouldn't need to call your program's main function within the program. If there's certain functionality common between main and another function, it should be given its own function or functions. As for your main function not running, it seems to me that if your program run without it in the first place, the function you call main may not be the REAL main...but I could be wrong, I have very limited experience with Borland C++ 6

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    124
    thanks for the reply...i'm not trying to call main from within my program...the structure is as given in the first post...i just need to implement:

    Code:
    main (int argc, char *argv[])
    {
    
    }
    i want to use this main to call the functions in my program rather than doing so by clicking buttons on a form...

    Regards,

    Farooq

  4. #4
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    If you want main() to run, you'll probably need to create a console application. And if it's a console application, then your buttons won't show up and work as you expect them to. Try looking for a form_load event or something in your documentation (a bit of a wild try, taken from Visual Basic since the Borland stuff seems to mirror VB pretty closely) and use that. Otherwise, learn Windows API or MFC if you want both buttons and a main() that runs on program startup.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    197
    it might be that boarland is using a different name for its "main", I know Microsofts will do this, for there Visual C++. Look through the code and see if you can find any other function with "main" as part of the name, it might be that one.

  6. #6
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Location
    Mt. Prospect, IL
    Posts
    2,572
    or maybe simply run it in a console

    then you will need to extract the command line argument from argv. This has also been covered many times before. Search for "command line argument(s)" on this board.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  7. #7
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Location
    Mt. Prospect, IL
    Posts
    2,572
    or better yet, LOOK THROUGH THE FAQ. I always forget about that too...

    http://faq.cprogramming.com/cgi-bin/...&id=1043284392

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  8. #8
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    axon: Given that he's using a GUI, that doesn't really apply. Of course, since he's a beginner, he should be using a console program anyway, but since he's using a GUI already that's somewhat irrelevant.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Like the MFC, Borland's class library probably uses an internal WinMain (not main...). Since you're using this library, look for a class of yours that is probably wizard-generated and was derived from TApplication or something similar. Look into the documentation of TApplication. The class should have a member (variable or function) that gives you access to the command line. You can access this through the main application object.

    In MFC, this would be the m_szCmdLine member of CApplication, and you would access it like
    AfxGetApp()->m_szCmdLine;
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 12:49 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM

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