Skip to content

Instantly share code, notes, and snippets.

@udaya1223
Last active October 5, 2016 06:29
Show Gist options
  • Save udaya1223/927185e5c1cfa7fba63543121265a054 to your computer and use it in GitHub Desktop.
Save udaya1223/927185e5c1cfa7fba63543121265a054 to your computer and use it in GitHub Desktop.
Formatting a file name using user input.
#include <sstream>
#define IMAGE_FILE_PATH "../../data/WideAngle"
#define LEFT_IMAGE_FILE_PATH "../../data/WideAngle"
#define LEFT_PREFIX "left_"
#define RIGHT_PREFIX "right_"
#define IMG_NUM_PAD (4)
#define IMG_EXTENSION "bmp"
#define START_FRAME_NUM (1)
#define END_FRAME_NUM (10)
using namespace std;
string ZeroPadNumber(int num, int pad){
stringstream ss;
// The number is converted to string with the help of stringstream
ss << num;
string ret;
ss >> ret;
if(pad < 1){
return ret;
}else{
// Append zero chars
int str_length = ret.length();
for (int i = 0; i < pad - str_length; i++)
ret = "0" + ret;
return ret;
}
}
int main(void){
char szFilePath[512];
for(int i=START_FRAME_NUM; i<=END_FRAME_NUM; i++) {
sprintf(szFilePath, "%s/%s%s.%s", LEFT_IMAGE_FILE_PATH, LEFT_PREFIX, ZeroPadNumber(i, IMG_NUM_PAD).c_str(), IMG_EXTENSION);
printf("%s\n", szFilePath);
sprintf(szFilePath, "%s/%s%s.%s", RIGHT_IMAGE_FILE_PATH, RIGHT_PREFIX, ZeroPadNumber(i, IMG_NUM_PAD).c_str(), IMG_EXTENSION);
printf("%s\n", szFilePath);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment