Solved

_strnset behaving differently while executing in release mode

Posted on 2013-05-30
2
192 Views
Last Modified: 2013-10-23
Hello Experts

Following is the code which appends spaces to a CString.
		long l_no_of_chars = 100;
		LPSTR t_space_text = NULL;
		CString u_space;

		//	Allocate that much space
		t_space_text = (LPSTR) malloc (l_no_of_chars + 1);
		//	Fill the variable with 32
		_strnset( t_space_text, 32, l_no_of_chars);	
		//	Set the Last Character
		*(t_space_text + l_no_of_chars) = 0;
		//	Get the Left Text
		u_space = t_space_text;
		::MessageBox (NULL,"File", u_space, MB_OK | MB_ICONINFORMATION);

		//	Free allocated memory
		free (t_space_text);

Open in new window

When I excute in release mode MessageBox is not displaying spaces  and when I debug in the release mode it is showing.

Please help in getting resolved, Thanks in advance.
0
Comment
Question by:HarishMinu
2 Comments
 
LVL 8

Accepted Solution

by:
Subrat (C++ windows/Linux) earned 500 total points
ID: 39212345
Try using safer version _strnset_s instead of _strnset(Deprecated One).
I hope in release ver. due to code optimization, it might be truncating spaces...
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel Hangs / Not enough Memory 5 91
Unresolved External Symbols 3 80
Access DB on open (All Objects) 5 63
What is sub-make ? 2 58
The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now