Use of a sprintf ( ) function ?

This is a discussion on Use of a sprintf ( ) function ? within the C Programming forums, part of the General Programming Boards category; Hi, the following code is a part of my project. Actually its a game where user throws an object in ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    18

    Use of a sprintf ( ) function ?

    Hi, the following code is a part of my project. Actually its a game where user throws an object in parabolic path and it lands on the ground. The score is given depending on where the object lands. Now i am trying to store the variable " give_score" in an array, lets call it give_score_array[], but really struggling to do that. any help would be appreciated

    if (pos_x_projectile > WALL_R + 20 + 0 && pos_x_projectile <= WALL_R +20 + 30)
    give_score = give_score + scores[0];

    if (pos_x_projectile > WALL_R + 20 + 30 && pos_x_projectile <= WALL_R + 20 + 60)
    give_score = give_score + scores[1];

    if (pos_x_projectile > WALL_R + 20 + 60 && pos_x_projectile <= WALL_R + 20 + 90)
    give_score = give_score + scores[2];

    if (pos_x_projectile > WALL_R + 20 + 90 && pos_x_projectile <= WALL_R + 20 + 120)
    give_score = give_score + scores[3];

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    Erm, like this?
    Code:
    sprintf( give_score_array, "%d", give_score );

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    18
    thanks Salem,

    but the problem remains. you see, the user has 5 chances to throw an object and each time it lands somewhere on the ground and the score is given for that.

    scores are stored in array

    Code:
    int scores[10] = { 0,20,30,40,50,60,70,80 };
    now if i give user score for his first throw i store it another variable like this:

    Code:
    give_score = give_score + scores[1]
    This will award user score of 20

    Now i need to store the scores for 5 throws in another array called get_score_string. how do i do that. I am not sure about the type of this array (int or char) and about its size.

    also i tried your code and it just gave garbage value.

    thanks

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    So how about starting with
    int scoreForEachThrow[5];

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

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