Thread: C strings

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    2

    C strings

    Im working on hardware interfacing with C and atm using an LCD screen to debug it. The LCD code takes a string and prints it to the LCD. My question is how can I make the string take values in the manner of printf statements?

    EG:

    int n;
    char *str;
    n=5;

    Id like to do something along the lines of

    str=(" this is a string and a number %d, n");

    More to the point Im not sure how to save a string with a variable in it.

    Thanks for the help.

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    sprintf() perhaps! check it out here

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    2
    Quote Originally Posted by itCbitC View Post
    sprintf() perhaps! check it out here
    great that works thanks! Do you know how I could created a function that takes an arbitrary amount of strings? So I could use sprtintf to convert all needed variables then write a function say lprintf(str1, str2, etc) that would concatenate them all with white space. I think i know how to write the function but I dont know if its possible to do it for an arbitrary amount of inputs. Thanks again

  4. #4
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by Jspeake View Post
    great that works thanks! Do you know how I could created a function that takes an arbitrary amount of strings? So I could use sprtintf to convert all needed variables then write a function say lprintf(str1, str2, etc) that would concatenate them all with white space. I think i know how to write the function but I dont know if its possible to do it for an arbitrary amount of inputs. Thanks again
    Do you mean a function whose argument list changes? If that's the case then check out the one here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 03:24 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 08:07 PM
  3. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM
  4. damn strings
    By jmzl666 in forum C Programming
    Replies: 10
    Last Post: 06-24-2002, 02:09 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM