Thread: Passing strings to functions?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    12

    Angry Passing strings to functions?

    As the title implies i am trying to pass a string to a function, and i wondered if there is any way to do it without using pointers?

    Here is my situation
    I have a structure:
    Code:
    struct foot_item {
           char item_name[20];
           char item_class[10];
           char item_slot[10];
           int armor;
           int durability;
           int minimumlevel;
           int hpbonus;
           int mpbonus;
           int attackpowerbonus;
           int attackhitbonus;
           int spellpowerbonus;
           int spellhitbonus;
           };
    struct foot_item sabatons;
    And now i want to be able to initalize everything from a function
    Code:
    initialize_armor(sabatons,Plate,Feet,0,0,0,0,0,0,0,0,0);
    But i am having trouble passing the sabaton, plate and feet ones.
    forgot to write this, is it possible to use a variable if i want to modify a structure (sorry if i am a bit cryptic)
    something like?
    Code:
    variable.spellpowerbonus=20;
    Edit: Also, this is how the function looks like
    Code:
    void initialize_armor(char name, char item_class, char item_slot,
    int armor, int durability, int minimumlevel, int hpbonus, int mpbonus, 
    int attackpowerbonus, int attackhitbonus, int spellpowerbonus, int spellhitbonus);
    The reason i constructed my code this way was so that i could create a database of items (in this example boots)
    with different stats and properties, so i can have one pair of boots named "foot_item sabatons;"
    and the next maybe named "foot_item slippers;" but still with the same properties(ok, maybe not the same but the same kind of properties)
    if you have any better ideas on how to do it please post them as well - im trying to learn here
    Last edited by Afro; 09-30-2007 at 02:50 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing strings to functions and modifying them
    By diddy02 in forum C Programming
    Replies: 6
    Last Post: 08-11-2008, 01:07 AM
  2. Replies: 2
    Last Post: 07-03-2008, 11:31 AM
  3. Passing Structure Pointers to Functions
    By samus250 in forum C Programming
    Replies: 15
    Last Post: 03-20-2008, 03:13 PM
  4. Passing from functions in classes to another function in another class?
    By Robert_Sitter in forum Windows Programming
    Replies: 1
    Last Post: 12-13-2005, 07:46 AM
  5. passing strings from functions as the "return" part
    By fraktal in forum C Programming
    Replies: 8
    Last Post: 12-13-2005, 01:38 AM