const char and a variable

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

  1. Buschmaster
    Expand Collapse
    macrumors 65816


    Feb 12, 2006
    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. kpua
    Expand Collapse
    macrumors 6502

    Jul 25, 2006
    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. gnasher729
    Expand Collapse
    macrumors G5


    Nov 25, 2005
    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