Evaluating type identifiers (%d) in strings, in C -


i working on mac osx , using bash shell. working in c , trying create file renumber files. important part of code follows:

int i; (i=0; i<numberoffiles; i++) {     strcpy(filename,""); //set null     char append[formatlength]; //string being appended     sprintf(append,"%%0%dd", formatlength); //example output: %04d     strcat(filename,fileprefix); //attached prefix     strcat(filename,append); //attaches appended part     //missing code: part equvaluates %04d int i, such 0023. } 

this gets me correct string format looking (say formatlength=4): fileprefix+%04d. however, need evaluate %04d in string , evaluate i, files like: file0001, file0002, etc.

would have ideas. help.

if understand question correctly, should able say

char result[(sizeof fileprefix/sizeof (char)) + formatlength]; sprintf(result, filename, i); 

since filename looks "fileprefix%04d". desired filename stored in result. not recommend re-storing in filenameby saying sprintf(filename, filename, i) because filename may small (for example, when formatlength = 9).

note need (sizeof fileprefix/sizeof (char)) find size of fileprefix (which char*), , add formatlength see how many more chars need after that


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -