appending integer to strings in a function vs concatenation

This is a discussion on appending integer to strings in a function vs concatenation within the C Programming forums, part of the General Programming Boards category; I would like to concatenate strings and integers so that i produce something like this: Code: char *path " = ...

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    12

    appending integer to strings in a function vs concatenation

    I would like to concatenate strings and integers so that i produce something like this:
    Code:
    char *path " = "/home/myFolder%d/run%d.raw"
    //where %d is a integer specifier
    so that I can use it in some function
    Code:
    int min, max, folderNumber;
    someFunction(path, min, max);
    concatenating....
    Code:
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 12-24-2012, 03:52 AM
  2. concatenation of strings
    By cnu_sree in forum C Programming
    Replies: 2
    Last Post: 02-12-2008, 10: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, 05:36 PM
  5. String Library & Appending Integer :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 12-24-2001, 04:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21