Thread: appending integer to strings in a function vs concatenation

  1. #1
    Registered User
    Join Date
    Dec 2012

    appending integer to strings in a function vs concatenation

    I would like to concatenate strings and integers so that i produce something like this:
    char *path " = "/home/myFolder%d/run%d.raw"
    //where %d is a integer specifier
    so that I can use it in some function
    int min, max, folderNumber;
    someFunction(path, min, max);
    char fpath[256];
    char fpath1[512];
    char *string1 = "/home/myFolder";
    char fn[6] = "/run_"
    char ext[5] = ".raw";
    int start =0;
    int end = 10;
    for (int ifolder= 0; ifolder<20; ifolder++) {
      sprintf(fpath, "%s%d", string1, ifolder);
      sprintf(fpath1, "%s%s%d%s", fpath, fn, %d, ext);
       //then call someFunction 
     someFunction(fpath1, start, end); //or
     someFunction("/home/myFolder%d/run%d.raw", 0,10);
    //the point is doing sprintf(fpath1,....) causes me problems, as I want to append instead the integer variables "start" and "end"  in  someFunction(fpath1, start, end); I will be do complicated for loops in this function, hence the necessity to do append here

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 12-24-2012, 04:52 AM
  2. concatenation of strings
    By cnu_sree in forum C Programming
    Replies: 2
    Last Post: 02-12-2008, 11:23 PM
  3. Concatenation of strings as char pointers
    By sameerc in forum C Programming
    Replies: 11
    Last Post: 05-10-2005, 04:23 PM
  4. integer concatenation with string again...
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 03-11-2002, 06:36 PM
  5. String Library & Appending Integer :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 12-24-2001, 05:27 PM