Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

HOW to Remove Blanks from CString.

Posted on 2000-05-15
6
Medium Priority
?
462 Views
Last Modified: 2013-11-20
HI,
  i HAVE
 CString str;
 char STR [10]="hello world";
  strcat(STR,str);


later I have TEXTOUT(.....,STR);
It works fine, But STR contains some blank sapces at the end of the text. How di I remove them before printing?

0
Comment
Question by:mkjoshi
6 Comments
 
LVL 8

Expert Comment

by:Vinayak Kumbar
ID: 2810838
Hi,

How about doing like this.

CString str;
char STR [10]="hello world";
str += STR;

//From where blanks came!!!?
str.TrimLeft();
str.TrimRight();

Then
TextOut(..., str);

Try it out.

VinExpert
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2810872
Hi mkjoshi,

caution:
STR is defined in your code as a pointer to an array of 10 chars. "Hello world" needs an array of at least 12 chars (including the terminating zero).

char STR[12] = "hello world";

should solve the problem here.

It's just luck that the code doesn't crash...

ZOPPO
0
 
LVL 4

Accepted Solution

by:
captainkirk earned 80 total points
ID: 2811233
Might be cleaner to say:

CString str = "hello world";
str.TrimLeft();
str.TrimRight();
TextOut(...,str);
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 23

Expert Comment

by:chensu
ID: 2811243
The memory size allocated for STR is not enough. Make sure it can contain the string after strcat.
0
 
LVL 1

Expert Comment

by:ch_vasu
ID: 2812961
Hi,
Replace your code with this code and try out. This code should work

CString str;
char STR [100]="hello world";//Increase the size
CString strTemp;
strTemp.Format("%s%s",STR,str);//Append the string
strTemp.TrimLeft();//Remove space
strTemp.TrimRight();//Remove space
TextOut(...,strTemp.GetBuffer(0));

Vasudev
0
 

Author Comment

by:mkjoshi
ID: 2813077
It really solved my problem,
Thanks.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

876 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