Formatting a file name using user input.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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