Debug assertion failed (Buffer too small)

Hi, I wrote a code...I had to use "strcpy_s" in it...the program is compiling but I'm getting debug assertion failed...I researched a bit and found that this error occurs due to incorrect size in the "strcpy_s" parameters...but I double checked and my size is ok...I can't understand why it's not working...Any help will be welcomed....Anticipated thanks...

From the header file

1
2
3
4
5
6
7
8
9
  class CyclicShift
{
private:
	char fUpperCase[26];//A-Z
	char fLowerCase[26];//a-z

public:
	CyclicShift();


In the .cpp file (initializing the constructor)

1
2
3
4
5
6
CyclicShift::CyclicShift()
{
	strcpy_s(fUpperCase, sizeof fUpperCase, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
	strcpy_s(fLowerCase, sizeof fUpperCase, "abcdefghijklmnopqrstuvwxyz");
}
Your size is not ok. Char arrays are terminated by '\0' - to store 26 chars you need a length of 27. Also the parameter of sizeof should be in round braces.
Last edited on
Why do you use plain arrays and strcpy_s in a C++ program?
The C++ standard library offers various containers, algorithms and std::string that make code safer and simpler.
Topic archived. No new replies allowed.