URGENT: QUICK QUESTION ABOUT INITALIZING A VARIABLE (Define Statement)....

This is a discussion on URGENT: QUICK QUESTION ABOUT INITALIZING A VARIABLE (Define Statement).... within the C Programming forums, part of the General Programming Boards category; I have a really quick question, I have a bunch of define statements, but they aren't initializing. I believe I'm ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    54

    URGENT: QUICK QUESTION ABOUT INITALIZING A VARIABLE (Define Statement)....

    I have a really quick question, I have a bunch of define statements, but they aren't initializing. I believe I'm suppose to set them to "0", but haven't been successful in getting it correct....

    define example:
    Code:
    #define i1 "ROAST PRIME RIB "
    #define i1_p 12.45
    and I'm trying to implement it like this
    Code:
    printf(" A     %d \t\t%d",i1, i1_p);
    What exactly is the format for setting it to "0", and where should this be done, in the "main" function? or in the "menu" function where I am trying to initialize it?

    Thanks in advance, much appreciated!!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    1. This is CBoard. There has never been, and never will be, an urgent post here.
    2. You don't have any variables in this code to initialize.
    3. You should, if you have the time and get a chance, look up what "%d" means, especially in the context of printf.

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    54
    ^^
    clearly I'm a beginner and just looking for a little guidance, I think it's fairy obvious what I'm trying to do here and I'm sure you can see that, no need for an elitist attitude. If you want to help me then please I would appreciate it, but don't patronize me because i'm new to this language..

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    It's not at all obvious what you're trying to do here with 0, why you want a string to be 0, what you think that even means.

    il and il_p are not variables. #define is just search-and-replace, not creating a variable.

    The patronizing, such as it is, is not for being a beginner, but for putting your post title IN ALL CAPS and using "urgent". Read the forum rules, which are stickied at the top of each forum.

  5. #5
    Registered User
    Join Date
    Apr 2010
    Posts
    8
    Clearly we have no idea what you are trying to accomplish.

    I can guess at what you are trying to do with what your code says...but I doubt I'd be right.

    If you are trying to print the STRING, you'd use %s instead of %d.

  6. #6
    Registered User
    Join Date
    Sep 2009
    Posts
    54
    ^^
    okay I apologize, i should have offered more details in my explanation, and it is true I did not read the forum sticky, so for that i apologize...

    I looked into the proper use of %d as you mentioned, and yes I have to be using %s instead, thank you for that.

    essentially i am creating a point of sale menu application for a restaurant...
    I have define statements for all the iteams and prices....

    such as this for the first item:
    Code:
    #define i1 "ROAST PRIME RIB "
    #define i1_p 12.45
    I would like to call these define statements in the menu, and have figured out that I must do this:
    Code:
    i1[0];
    before calling it using %s.....


    However I cannot find out what specified I need to use to properly call the #define for the price......? help?

  7. #7
    Registered User
    Join Date
    Sep 2009
    Posts
    54
    i suppose i can just use %f for now...?

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by matt.s View Post
    i suppose i can just use %f for now...?
    You should %f forever. If you get a chance, still, you should read up on what %d means and why it is completely incorrect in your example.

  9. #9
    Registered User
    Join Date
    Sep 2009
    Posts
    54
    when i first did...

    Code:
    #define i1 "ROAST PRIME RIB "
    #define i1_p 12.45
    
    i1[0];
    printf(" A     %s \t\t%f",i1, i1_p);
    I was getting the desired result, now i1 is outputting as "<null>".......any ideas?

  10. #10
    Registered User
    Join Date
    Apr 2010
    Posts
    8
    Code:
    #define i1 "ROAST PRIME RIB "
    #define i1_p 12.45
    
    printf(" A     %s \t\t%f",i1, i1_p);
    output:
    Code:
    A ROAST PRIME RIB           12.45
    Is this what you are trying to do?

  11. #11
    Registered User
    Join Date
    Sep 2009
    Posts
    54
    ^^^
    Yes!
    seems to be working now, although with the same code I1 was coming up as <null> earlier...lol

    thanks for the help guys.

  12. #12
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by matt.s View Post
    when i first did...

    Code:
    #define i1 "ROAST PRIME RIB "
    #define i1_p 12.45
    
    i1[0];
    printf(" A     %s \t\t%f",i1, i1_p);
    I was getting the desired result, now i1 is outputting as "<null>".......any ideas?
    1. i1[0]; does nothing.
    2. The code you posted shouldn't have any problems, but if you've done something interesting around this code ... well you still shouldn't have any problems really. If you put that i1[0] inside the printf, for instance, you would have problems.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 05-13-2007, 08:55 AM
  2. Question about printing a variable???
    By Hoser83 in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2006, 12:57 PM
  3. Please STICKY this- vital to MSVC 6 dev - BASETSD.h
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 03-15-2005, 08:22 AM
  4. build errors migrated from dx9b to dx9c sdk
    By reanimated in forum Game Programming
    Replies: 4
    Last Post: 12-17-2004, 06:35 AM
  5. LISP (DrScheme) any one?
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-31-2004, 11:52 AM

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