Functions are Still Not Understood.

This is a discussion on Functions are Still Not Understood. within the C Programming forums, part of the General Programming Boards category; I need help because I cant seem to understand how functions work with arguments and structures. I have this function ...

  1. #1
    Registered User errigour's Avatar
    Join Date
    Mar 2009
    Posts
    102

    Functions are Still Not Understood.

    I need help because I cant seem to understand how functions work with arguments
    and structures.

    I have this function in a program,
    void do_cast(struct char_data *ch, char *argument, int cmd, int subcmd)

    with a lot of code I could post for you if you want to help me change it.

    What I need help with is understanding how
    a) the function will return the structure
    b) how to return the structure when using do_cast
    c) how the function will return the char *argument
    d) how the function will return the int cmd
    e) and how the function will return the int subcmd

    Basically I need help understanding how a function returns its variables
    from the computer language inside its brackets and how to use the function
    and its variables in a c program.

    This isn't my homework, I really have a program that has that function. I also
    tried learning how to use functions from c programming.com without any
    luck so i'm hoping someone can explain functions to me so that I might understand
    how to use them proficiently or even well enough to make a useful program
    function. If someone would help me understand these how to's then i will
    understand functions. that is why i posted the question and also so that
    whoever reads my questions may understand the question I am asking. I
    repeat again I am not asking for homework help. I do not go to school.

    If anyone has some extra time on there hands I Would like to know how to make a
    useful command line argument for a telnet program. Maybe something cool that
    you have on your mind or have used or a liked that feature when using a telnet
    program or any program that accepts command line arguments.
    Last edited by errigour; 04-09-2009 at 04:32 AM.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Anything that hasn't got a star in the parameter list can not be modified outside of the function itself. Whether it "returns" with any of the other parameters modified or not is a matter of what the function itself does, and we can not tell that from the prototype declaration that you have posted.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User errigour's Avatar
    Join Date
    Mar 2009
    Posts
    102

    i dont understand functions

    Basically I need help understanding how a function returns its variables
    from the computer language inside its brackets and how to use the function
    and its variables in a c program.

    If you want to spend a little time explaining that thanks.

  4. #4
    Registered User errigour's Avatar
    Join Date
    Mar 2009
    Posts
    102

    If anyone has some extra time....

    If anyone has some extra time on there hands I Would like to know how to make a
    useful command line argument for a telnet program. Maybe something cool that
    you have on your mind or have used or a liked that feature when using a telnet
    program or any program that accepts command line arguments.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Right, that's quite a lot of understanding to gain. I think you need to start with a slightly less complex task from what it looks like.

    Trying to understand fairly complex code simply by reading the code by itself is like trying to read a foreign legal document using a dictionary - it's not going to work!

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    575
    The law of rapid experience-gaining: "one gains experience the fastest and easiest by doing things at their own level and no higher or lower". In this case, it's like a second-grader being assigned 10th grade work - it's hard and frustrating. Tone down the difficulty a lot so that it is at your skill level. Try this. Have a function return a value 5 higher than what was fed to it. This is the easiest you can get for learning functions. Got that mastered? Okay, try having the function accept a pointer to a value and return 5 more to it. Just work your way up but keep at your own level. Take it too easy and it'll be boring and you won't get experience quickly (like a tenth-grader being assigned second-grade work). Take it too hard and it'll be frustrating and confusing halting experience (like a second-grader being assigned tenth grade work). Do it at your level, and the challenge is acceptable and the experience comes quickly. I've used this "law" to improve on my comprehension skills - from the 4th grade level (in 11th grade) to about grade 7 by the end of high school. This applies to anything, including programming (and I'm using it with programming as well).
    High elevation is the best elevation. The higher, the better the view!
    My computer: XP Pro SP3, 3.4 GHz i7-2600K CPU (OC'd to 4 GHz), 4 GB DDR3 RAM, X-Fi Platinum sound, GeForce 460, 1920x1440 resolution, 1250 GB HDD space, Visual C++ 2008 Express

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,261
    Quote Originally Posted by ulillillia View Post
    The law of rapid experience-gaining: "one gains experience the fastest and easiest by doing things at their own level and no higher or lower". In this case, it's like a second-grader being assigned 10th grade work - it's hard and frustrating. Tone down the difficulty a lot so that it is at your skill level. Try this. Have a function return a value 5 higher than what was fed to it. This is the easiest you can get for learning functions. Got that mastered? Okay, try having the function accept a pointer to a value and return 5 more to it. Just work your way up but keep at your own level. Take it too easy and it'll be boring and you won't get experience quickly (like a tenth-grader being assigned second-grade work). Take it too hard and it'll be frustrating and confusing halting experience (like a second-grader being assigned tenth grade work). Do it at your level, and the challenge is acceptable and the experience comes quickly. I've used this "law" to improve on my comprehension skills - from the 4th grade level (in 11th grade) to about grade 7 by the end of high school. This applies to anything, including programming (and I'm using it with programming as well).
    Actually that's some really great advice there!
    Do projects where you're pretty sure you know how to do about 80-90% of it, and you're pretty sure you can figure out how to do the remaining percentage.
    I only once ever wrote a game where I knew how to do the whole thing from the get go. Most boring four hours of programming I ever spent. Throw me in the deep end though and I'll be constantly wishing I was somewhere else.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 02:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM

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