In my vc++ code,
I want to change a filename xxx.000001.log to xxx.000002.log, xxx.000003.log.... using CString.
struct idx_name{
char type[4];
char digit[6];
char ext[4];
}
idx_name idx_logname;
memset(&idx_logname, 0, sizeof(idx_logname));
memcpy(&idx_logname, fname, sizeof(idx_logname));
CString s = CString(idx_logname.digit).GetBufferSetLength(6);
int idx = _ttoi(s);
idx++;
::ZeroMemory(&idx_logname.digit, sizeof(idx_logname.digit));
sprintf_s(idx_logname.digit, sizeof(idx_logname.digit), "%06d", idx);
::ZeroMemory(filename, sizeof(filename));
memcpy(filename, &idx_logname, sizeof(idx_logname));
CString folder = CString(Current_folder);
s = folder + CString(filename);
This has no compile error.
But in the run time, process has running error at the line of "sprintf_s" like as
"Expression : ("Buffer too small",0);
As a novice of VC++, please let me know the error and who knows the simple ways to change filenames?
What I have tried:
One day wasted for this problem.