Thread: printf-like function ?

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    7

    Question printf-like function ?

    Hi folks,

    New to C, quick question about string manipulation.
    I need a highly efficient function to replace parameters in a string, basically the same way that printf works.

    char *template = "foo %s bar %s ...";
    newString = replaceParams(template, "param1", "param2");

    Is it possible to just redirect printf ? (as long as printf is efficient)
    Otherwise whats my best option (algorithm)?

    Thx

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Maybe strcpy and sprintf is what you are looking for. google them. To be honest I didn't really understand you
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    7
    Good enough! I didn't know about sprintf, thats all I really needed. Thanks!

  4. #4
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Happy that helped! Also, welcome to the forum and have a happy && healthy new year!
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very simple Function using printf()
    By twazzler in forum C Programming
    Replies: 17
    Last Post: 04-14-2011, 05:04 PM
  2. printf() function definition
    By saswatdash83 in forum C Programming
    Replies: 2
    Last Post: 07-24-2008, 07:34 AM
  3. Simulating printf function
    By wu_weidong in forum C Programming
    Replies: 2
    Last Post: 03-20-2005, 12:14 PM
  4. printf like function
    By tyouk in forum C Programming
    Replies: 5
    Last Post: 11-17-2003, 07:26 PM
  5. printf like function
    By argon in forum C Programming
    Replies: 2
    Last Post: 10-07-2003, 03:12 PM