-
sprintf funcionality
Hi,
i already googled it but i couldn't found an adequate answer so here it goes.
Im trying to replace the instruction:
sprintf (command, "rename %s_TypeA_%04d %s_TypeA_%04d.yuv\n", videofile, i, videofile, i);
which is a windows system command to rename files and i intend to run it for a long sequence of frames.
The objective here is to replace the manually inserted %04d for a variable which tells you the length of the sufix, something like as follows:
sprintf (command, "rename %s_TypeA_%0%dd %s_Base_%0%dd.yuv\n", videofile, i, sufix, videofile, i, sufix);
I cant get this working as it returns an error at output.c "Unhandled exception at 0x6642984f (msvcr90d.dll) in my_program.exe: 0xC0000005: Access violation reading location 0x00000001."
I am hoping that someone can give me an advice to solve this.
-
You mean this?
Code:
sprintf(command, "rename %s_TypeA_%0*d %s_Base_%0*d.yuv\n",
videofile, i, sufix, videofile, i, sufix);
-
Quote:
Originally Posted by
hk_mp5kpdw
You mean this?
Code:
sprintf(command, "rename %s_TypeA_%0*d %s_Base_%0*d.yuv\n",
videofile, i, sufix, videofile, i, sufix);
No, that will output if sufix=2(along the for cycle and if you replace sprintf with a printf):
rename videofile_TypeA_2 videofile_TypeA_2.yuv
rename videofile_TypeA_02 videofile_TypeA_02.yuv
rename videofile_TypeA_002 videofile_TypeA_002.yuv
rename videofile_TypeA_0002 videofile_TypeA_0002.yuv
What i want to do:
rename videofile_TypeA_00 videofile_TypeA_00.yuv
rename videofile_TypeA_01 videofile_TypeA_01.yuv
rename videofile_TypeA_02 videofile_TypeA_02.yuv
rename videofile_TypeA_03 videofile_TypeA_03.yuv
or
rename videofile_TypeA_000 videofile_TypeA_000.yuv
rename videofile_TypeA_001 videofile_TypeA_001.yuv
rename videofile_TypeA_002 videofile_TypeA_002.yuv
rename videofile_TypeA_003 videofile_TypeA_003.yuv
or
rename videofile_TypeA_0000 videofile_TypeA_0000.yuv
rename videofile_TypeA_0001 videofile_TypeA_0001.yuv
rename videofile_TypeA_0002 videofile_TypeA_0002.yuv
rename videofile_TypeA_0003 videofile_TypeA_0003.yuv
according to the value of sufix.
-
Switch suffix and i in your print statement, then.
-
First question... why would you use a slow and error prone system call and not use the MoveFile() function built into windows?
Combine this with FindFirstFile() FindNextFile() and FindClose() and it's a pretty simple task to sweep through a folder, locate files and rename them.
And it's going to be 5 or 10 times faster than system calls...
-
Thank You
Thanks for the answers.
I already switched it. when I answered you i was in a hurry and just experimented your code and didn't even analyzed it as i should've, because i had never used * operand inside sprintf. So switching them ocurred me in a class I was attending as a pretty simple thing to do and i was already thinking i would be mocked by that when i come back here :p
Above the second answer, i dont know those functions but i will certanly take a look at them.
So thank you all for the tips. It was the first time I used this forum and I'm very pleased with it. I'll certanly come back to help and be helped if I need so.