Like Tree1Likes
  • 1 Post By CommonTater

Compiling multiple source codes

This is a discussion on Compiling multiple source codes within the C Programming forums, part of the General Programming Boards category; Right now my program is getting way to complex for me to handle it all on one .C file. So ...

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    117

    Compiling multiple source codes

    Right now my program is getting way to complex for me to handle it all on one .C file.

    So I decided to clean it up with the knowledge I acquired since I made it.
    I could make a function for it, which I have tried, but failed because I couldn't pass a string to a function for some reason that I do not know. I tried looking it up on google but... those people write their tutorials in a way I do not understand

    Anyways, I opted to learn how to compile multiple source code files as I will need to learn it latter on anyways.

    You guys help me so much I feel like I should pay you somehow :S

    Here are the two source code files:
    calc_valance.C
    Attached Files Attached Files
    • File Type: c LS.C (7.2 KB, 38 views)

  2. #2
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Although the code is in C++, the idea is the same. Take a look at How to work with multiple source files-FAQ.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,458
    Quote Originally Posted by JonathanS View Post
    Right now my program is getting way to complex for me to handle it all on one .C file.

    So I decided to clean it up with the knowledge I acquired since I made it.
    I could make a function for it, which I have tried, but failed because I couldn't pass a string to a function for some reason that I do not know. I tried looking it up on google but... those people write their tutorials in a way I do not understand
    Try some of our tutorials, maybe they'll help: Cprogramming.com - Programming Tutorials: C++ Made Easy and C Made Easy.

    Your passing a string to a function issue is because your declared your function to take a char, not a char *. Also, your prototype is incorrect. You specify the type without a variable name, not the name without a type. The purpose of the prototype is so the compiler can check your usage: correct number and type of params, and correct return type.

    You need to work on further breaking your code into functions. Your calc_valence function is a good start, but you could do a lot more. Your calc_valence function would benefit greatly from using an array to map element names to valence electrons. Also, you don't need compare or VEtemp:
    Code:
    int calc_valence(char *element)  // note the * to signify pointer to character, which is typically how you pass strings in C
    {
        if (strcmp(element, "B") == 0)
            return 3;
        if strcmp(element, "C") == 0)
            return 4;
        ...
        return -1;  // check the return value in main, and report "Invalid element" if it's -1
    }
    You have 3 while loops in your main that are essentially the same, make one into a function, and call it 3 times, one with max1, VE, a1, a2 and a3; another with max2, VE, b1, b2 and b3, etc. Move your input gathering code into one funciton and your output code into another function.

    You guys help me so much I feel like I should pay you somehow :S
    Pay it forward. None of us came here to make money from our posts. As you learn and become knowledgeable and an expert in your field, take some time to help out those who are struggling like you once were.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by anduril462 View Post
    Pay it forward.
    Absolutely... It all comes full circle eventually...

    (Good movie, as well)

  5. #5
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by CommonTater View Post
    (Good movie, as well)
    Helen Hunt....'nough said.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by AndrewHunter View Post
    Helen Hunt....'nough said.
    Yep... 'bout As Good As It Gets

    (Sorry, couldn't resist)
    AndrewHunter likes this.

  7. #7
    Registered User
    Join Date
    Sep 2011
    Posts
    117
    Right now this is a bit much for me.

    Surly I'll learn this latter, but right now I have made the program with different functions, and am fairly (ok VERY) happy with it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compiling multiple source files
    By jtieu in forum C++ Programming
    Replies: 4
    Last Post: 03-29-2011, 06:51 PM
  2. Source codes
    By geek@02 in forum Windows Programming
    Replies: 2
    Last Post: 10-22-2006, 01:54 PM
  3. Using multiple source codes
    By GamingMarvel in forum C++ Programming
    Replies: 10
    Last Post: 01-21-2005, 06:16 AM
  4. Replies: 1
    Last Post: 05-01-2003, 02:52 PM
  5. vc++ source codes
    By Cprogrammer in forum C++ Programming
    Replies: 4
    Last Post: 09-29-2001, 12:57 PM

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