Thread: Join variable with string

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    3

    Join variable with string

    Hi,

    I'm trying to convert a C# program to a C version and I'm encountering all sorts of little problems. I try to solve them as a go along, but I can not figure out how to do the following:

    in C# I have (table_name is a string variable):

    string query = "SELECT * FROM " + table_name + " LIMIT 100";

    I would like to translate that line to C, but the support for strings is not that great. I have experimented with strcat and strcpy, but I can not get it to work. All help is welcome. Thanks.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Look into something like sprintf.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    3
    Thank you very much, sprintf did the trick.

    The solution for my problem was:

    char q[100];
    sprintf(q, "SELECT * FROM %s LIMIT 100", table_name);
    Last edited by nicksnels; 03-23-2010 at 04:39 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  4. can anyone see anything wrong with this code
    By occ0708 in forum C++ Programming
    Replies: 6
    Last Post: 12-07-2004, 12:47 PM
  5. Variable Allocation in a simple operating system
    By awkeller in forum C Programming
    Replies: 1
    Last Post: 12-08-2001, 02:26 PM