Thread: Add var and txt to var

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    2

    Add var and txt to var

    Hello Guys!

    I'am programming a lpc2148 and all works quite well. But I have one small problem, I want to use a function but I have multiple out.

    Here is what i have:
    Code:
    int functionAnimatie(unsigned int intVar){
      varTwo= out + intVar;
    }
    Here is 'out' just text and 'intVar' a number. My problem is: I want to couple the text and the number to: out1 if the number is 1 or out2 if the number is 2.

    I don't know how I can do it and also can't find it on the internet.
    Can one of you help me out?

    Thanks in advance,
    BBasje

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Eh? Come again? I didn't really understand all that. Anyone else did?
    What exactly are you trying to do?

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you need to convert an integer to text, you need to use some function - this is not PHP where you can just make something a string and append any other variable to it and automatically it becomes a string.

    In this case, I think you want sprintf().

    That is, if I understood the question correctly [well, the only ACTUAL question in there should be answered with a "Yes" - there's someone that can help you.]

    --
    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.

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    2
    Excuse me for my english :-P

    In the programming code, I need to get the outcome of 'out' in combination with 'intVar'.

    If 'intVar = 1', I want to get 'out1'.
    If 'intVar = 2', I want to get 'out2'.

    I have little programming experience, so I don't know how to get that working.
    Does anyone of you have a solution for this problem?

    I can't use the 'sprintf()' command, because I need the outcome as a number in the program, so I can use it again in another string.

    I hope this is clear enough though :-P

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Sorry, but I don't follow that: You can't use sprintf() because it creates a string, but you want a string that is "outX" where X is your intVar? Or do you want a numeric value that represents the four characters 'o', 'u', 't', 'X' [where X is a digit?]

    --
    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
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I believe what you want is to combine the number and the string. So far example if intVar is 1, the results becomes "out1", yes?
    This is a string, not a number, so I'm not sure why you say you can't make a string? It doesn't make sense to what you're doing?
    sprintf can create a string for you from a number.

  7. #7
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    What type is "out"?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed