这段代码的主要错误是什么? [英] What is the main error of this code?

查看:110
本文介绍了这段代码的主要错误是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的vc ++代码中,



我想将文件名xxx.000001.log更改为xxx.000002.log,xxx.000003.log ... 。使用CString。



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));

        // get the char fname[100]; = "xxx.000001.log"
	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));

        // get Current_folder as current_directory
	CString folder = CString(Current_folder);
	s = folder + CString(filename);



这没有编译错误。

但是在运行时,进程已经运行sprintf_s行中的错误如



表达式:(缓冲区太小,0);



作为VC ++的新手,请告诉我错误,谁知道更改文件名的简单方法?



我试过的:



浪费了一天这个问题。


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.

推荐答案

引用:

表达式:(缓冲区太小,0);

"Expression : ("Buffer too small",0);



您尝试存储'/ 0 '在大小为6的缓冲区中终止了大小为6的字符串。

大小为6的'/ 0'终止字符串为6 + 1,因此它是7.

检查时,尝试使用更大的缓冲区。


You try to store a '/0' terminated string of size 6 in a buffer of size 6.
A '/0' terminated string of size 6 is 6+1, so it is 7.
Just for checking, try to use a larger buffer.


这篇关于这段代码的主要错误是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆