const char and a variable

Discussion in 'Mac Programming' started by Buschmaster, Jan 21, 2009.

  1. macrumors 65816

    Buschmaster

    Joined:
    Feb 12, 2006
    Location:
    Minnesota
    #1
    I'm working with SQLite so that's why I need a const char, otherwise I'd know exactly how to do this, no problem at all.

    Unfortunately I haven't spent much time with the char data type.

    Here's my question...

    What I have is a string and then a variable to put at the end of the string. How can I format this so I can put the variable at the end of the string? If I were working with an NSString this is what I'd be trying to accomplish:
    That's just an example but almost exactly what I'm trying to accomplish, just not inside my const char. Any ideas?
     
  2. macrumors 6502

    Joined:
    Jul 25, 2006
    #2
    Your question isn't really clear, but I assume you're asking how to do something like -stringWithFormat: using C strings.

    Take a look at sprintf. -stringWithFormat: is essentially a wrapper around that function.

    Or, you could build an NSString and then get the C string from it.
     
  3. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #3
    Before you do anything else, google for "SQL injection".

    What would happen if you take the name from a text field, and the user types the following into the text field:

    Your code probably puts quotes around the name, turning it into

    and your SQL statement becomes

    and everything is zapped.
     

Share This Page