Click here to Skip to main content
15,910,787 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionhelp in shape extraction from images Pin
bhamaimrith22-Sep-05 16:14
bhamaimrith22-Sep-05 16:14 
Questionhow do I print a string with " " " in it Pin
Spiritofamerica22-Sep-05 14:08
Spiritofamerica22-Sep-05 14:08 
AnswerRe: how do I print a string with " " " in it Pin
Shog922-Sep-05 14:26
sitebuilderShog922-Sep-05 14:26 
Questiontrim? Pin
kerrywes22-Sep-05 12:42
kerrywes22-Sep-05 12:42 
AnswerRe: trim? Pin
Chris Losinger22-Sep-05 13:39
professionalChris Losinger22-Sep-05 13:39 
AnswerRe: trim? Pin
Nemanja Trifunovic22-Sep-05 15:54
Nemanja Trifunovic22-Sep-05 15:54 
GeneralRe: trim? Pin
kerrywes22-Sep-05 17:10
kerrywes22-Sep-05 17:10 
GeneralRe: trim? Pin
Christian Graus22-Sep-05 17:13
protectorChristian Graus22-Sep-05 17:13 
use ::strcpy to copy the rest of the string from that position down one. Make sure you copy the null at the end as well.



Christian Graus - Microsoft MVP - C++

-- modified at 23:21 Thursday 22nd September, 2005

Here's a solution:

#include "stdafx.h"

#include <iostream>

using namespace std;

size_t trim(char * str)
{

size_t len = ::strlen(str);

for(size_t i =0; i < len; ++i)
{
if (::isspace(str[i]))
{
::strcpy(&str[i], &str[i+1]);

-- len;
}
}

return len;

}

int _tmain(int argc, _TCHAR* argv[])
{
char * str1 = new char[200];

strcpy(str1, " This is a test of the veracity of my system..... ");

cout << strlen(str1);
cout << trim(str1);
cout << str1;

cin >> str1;

return 0;
}

GeneralRe: trim? Pin
Jose Lamas Rios22-Sep-05 18:26
Jose Lamas Rios22-Sep-05 18:26 
GeneralRe: trim? Pin
Christian Graus25-Sep-05 12:12
protectorChristian Graus25-Sep-05 12:12 
GeneralRe: trim? Pin
Jose Lamas Rios25-Sep-05 16:03
Jose Lamas Rios25-Sep-05 16:03 
Questionstrange char* problem Pin
ddmcr22-Sep-05 11:24
ddmcr22-Sep-05 11:24 
AnswerRe: strange char* problem Pin
Christian Graus22-Sep-05 12:30
protectorChristian Graus22-Sep-05 12:30 
GeneralRe: strange char* problem Pin
Cedric Moonen22-Sep-05 20:10
Cedric Moonen22-Sep-05 20:10 
AnswerRe: strange char* problem Pin
Cedric Moonen22-Sep-05 20:15
Cedric Moonen22-Sep-05 20:15 
GeneralRe: strange char* problem Pin
Steen Krogsgaard22-Sep-05 21:07
Steen Krogsgaard22-Sep-05 21:07 
GeneralRe: strange char* problem Pin
ddmcr22-Sep-05 22:24
ddmcr22-Sep-05 22:24 
GeneralRe: strange char* problem Pin
Steen Krogsgaard22-Sep-05 22:51
Steen Krogsgaard22-Sep-05 22:51 
GeneralRe: strange char* problem Pin
ddmcr22-Sep-05 23:00
ddmcr22-Sep-05 23:00 
GeneralRe: strange char* problem Pin
ddmcr22-Sep-05 22:29
ddmcr22-Sep-05 22:29 
AnswerRe: strange char* problem Pin
toxcct22-Sep-05 21:43
toxcct22-Sep-05 21:43 
QuestionRe: strange char* problem Pin
ddmcr22-Sep-05 22:18
ddmcr22-Sep-05 22:18 
AnswerRe: strange char* problem Pin
toxcct22-Sep-05 22:26
toxcct22-Sep-05 22:26 
GeneralRe: strange char* problem Pin
ddmcr22-Sep-05 22:29
ddmcr22-Sep-05 22:29 
QuestionMFC with Windows Form App (.NET) like controls Pin
lordgreg22-Sep-05 10:31
lordgreg22-Sep-05 10:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.