Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Easy C Question

Options
  • 02-08-2001 11:42am
    #1
    Closed Accounts Posts: 35


    Just a simple C question from a C newbie. I'm writing a C project and to make things tidier, I want to put some of the principal functions in another source file. You probably say that to make it a header file yes, but I want the second source file in the same folder as the first. Put me out of my misery. I know I'ts easy and embarrasment is knocking on the door....


    I like blinking I do!

    Narf!!!


Comments

  • Registered Users Posts: 2,494 ✭✭✭kayos


    <font face="Verdana, Arial" size="2">Originally posted by Trojan:
    Yeah Kaelen (gawddamn spelling smile.gif !!) is on the mark there</font>

    Cool two years down the road and I can still get things right see I'm not just a VB muppet I used know C/C++ and I hope to start learning it again once I can manage to get the boss to ease up on my workload. As for the spelling al your getting there its Kealan.

    Ah it feels good to have got that question right and have it endorsed my the man himself Big Al smile.gif




    kayos
    When you get to hell tell them I sent you,
    you'll get a group discount...

    tribes.gameshop.ie


  • Closed Accounts Posts: 1,322 ✭✭✭phobos


    Lightweights!

    Richey, listen to Trojan, he's our resident C/C++ guru, and also a good m8. He also took the words out of my mouth.

    Al, I can assume this is a small C project, so wouldn't it make sense to simply put the prototypes and definitions in the header file and simply import that in to the main source file. A suggestion.

    Christ, I love that structured C/C++ command line stuff.
    Private Sub Command1_Click()
        
        MsgBox "I'm a Microsoft Muppet"
        
    End Sub
    
    Only jokin Kealan tongue.gif

    ;-phobos-)

    [This message has been edited by phobos (edited 02-08-2001).]


  • Registered Users Posts: 2,494 ✭✭✭kayos


    Whats stopping you putting it in a header file in the same folder??? Its been a long time since I've done C/C++ but that worked for me in a Comp Eng project in Electronics which was bacilly loads of labs got to do with controlling and reading hardware and then combine all of the labs in one project and have a nicve flashy (well flashy Borland DOS BGI) UI. I remember just spliting out the indivdual labs into headers and having a very very small c file just to start up the app and display the menu. If I remember right if you do this
    #include &lt;iostream.h&gt; // Adds a header file from the system path for header files
    #include "myfile.h" //adds a header file from you project location
    

    please do not flame me for this I haven't touched C/C++ in over 2 years so I'm very rusty on the topic. But its worth a try if no one else posts up.


    kayos
    When you get to hell tell them I sent you,
    you'll get a group discount...

    tribes.gameshop.ie


  • Registered Users Posts: 16,402 ✭✭✭✭Trojan


    Yeah Kaelen (gawddamn spelling smile.gif !!) is on the mark there, you could have something like the following:

    (main.c)
    #include "myfunc.h"
    ...
    

    (myfunc.h)
    int myfunc1(int); /* prototype */
    ...
    

    (myfunc.c)
    int myfunc1(int val) {
    /* implementation of function */
    }
    ...
    

    Just make sure to include the 2nd file in the compilation cmd line or project.

    Al.


  • Registered Users Posts: 16,402 ✭✭✭✭Trojan


    <font face="Verdana, Arial" size="2">Originally posted by phobos:
    Al, I can assume this is a small C project, so wouldn't it make sense to simply put the prototypes and definitions in the header file and simply import that in to the main source file. A suggestion.

    Christ, I love that structured C/C++ command line stuff.
    </font>

    Yeah it would, but he asked for something different smile.gif

    And I'm a junior code monkey, not a guru.

    Al.


  • Advertisement
  • Closed Accounts Posts: 35 The Pinky


    Ah **** it lads, don't be givin' out on my post, I only came here for an answer!!!


  • Closed Accounts Posts: 1,322 ✭✭✭phobos


    Richey, did you get it sorted out yet?

    If it is only a small project don't bother with writing function libraries. Unless you really think you can reuse the code somewhere else. I was coding in C for 2 years and only appended function libraries once in a blue moon.

    ;-phobos-)
    PS: What is it you're doing anyway?


  • Closed Accounts Posts: 35 The Pinky


    Westo, what I wanted to do was just do make everything look all pretty and nice because my code was getting all confusing and hard!!!! (I'm a newbie, I'm sorry!!!) I just wanted to tidy things up and put them in seperate C source files. It was just one of those crap programs that I make up and try to do (Remember my Countdown one???- Ugh)
    Anyway, thats the story m8.

    TTYL

    Richey


  • Closed Accounts Posts: 1,322 ✭✭✭phobos


    Richey,

    What is propose you do is try and keep everything in the same source file. I remember discussing the program you are on about, but it shouldn't be any more than a couple of simple functions to accomplish. I know it can be a bit confusing @ the start, but the best thing to do is to try and not make it hard on yourself, programming is funny like that. Remember keep it as simple as possible. Do you analysis on paper before you touch the keyboard. That way you will be able to determine how your program will be broken up in to functions etc before you start.

    When I'm writing structured stuff, I ask myself this question. "What things does this program do?". I write down the list, and I make a function for each. Remember it is often hard to find a balance between clever code and readable code. Hackers tend to write clever code that is short and sweet, but n00bs tend to write readable code (or so what it taught to them anyway).

    For now concentrate on getting your programs working, and worry about making them run faster later.

    Feel free to mail me some code if you want.

    ;-phobos-)


  • Registered Users Posts: 16,402 ✭✭✭✭Trojan


    I think really clean code is important, even in small programs: layout and proper identifiers and stuff, It really makes coding so much easier. Make sure your indentation is correct, it's not just important in code maintenance and debugging, it's essential.

    Use comment headers at the top of each file and function, giving filename, date created, modified, author, etc, and for each function, all parms and return value and description of what it does.

    Professional code is done this way for a reason. Also you can use the /** comments and javadoc to make some nice docs from it, you can get a C version of this too somewhere.

    Have a look at this page, then don't do any of it!! http://mindprod.com/unmain.html



  • Advertisement
Advertisement