You are not logged in.

#1 2005-09-07 04:20:35

Euphoric Nightmare
Member
From: Kentucky
Registered: 2005-05-02
Posts: 283

removing white space from a char[] (C)

Is there a function from the standard c library to do that for me?

Offline

#2 2005-09-07 09:07:09

STiAT
Member
From: Vienna, Austria
Registered: 2004-12-23
Posts: 606

Re: removing white space from a char[] (C)

standard c or c++?

in c++:

string::iterator it=temp.end();
temp.erase(remove(temp.begin(),temp.end(),' '),it);

to remove whitespaces of a string.


In c i'd rather use strtok:

char *as,*df;
as = strtok(str, " ");
while ((df = strtok(NULL, " ") != NULL)
{
    strcat (as,df)
    memset (df, 0, strlen (df));
}

Lg,
STi


Ability is nothing without opportunity.

Offline

#3 2005-09-07 20:13:39

Euphoric Nightmare
Member
From: Kentucky
Registered: 2005-05-02
Posts: 283

Re: removing white space from a char[] (C)

Nifty trick.  Thanks for the advice

Offline

#4 2005-09-07 22:11:19

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: removing white space from a char[] (C)

better to run a python instance and run string.trim()

RD&H

Dusty

Offline

#5 2005-09-08 01:39:15

Euphoric Nightmare
Member
From: Kentucky
Registered: 2005-05-02
Posts: 283

Re: removing white space from a char[] (C)

but if i use python i won't be a 1337 H4XX0RZ

Offline

#6 2005-09-08 02:22:26

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: removing white space from a char[] (C)

No, you'll be an efficient hacker...

Dusty

Offline

#7 2005-09-08 03:04:02

Euphoric Nightmare
Member
From: Kentucky
Registered: 2005-05-02
Posts: 283

Re: removing white space from a char[] (C)

Actually I was going to try to learn some python...I don't know what happened...

Offline

#8 2005-09-08 13:03:28

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: removing white space from a char[] (C)

Got bogged down in C! :-D

I don't understand when people who can program in one language say "I was going to learn Python". Python doesn't have to be learned. If you understand structured and/or object oriented programming, you know Python already; its just the natural syntax you would use.

I like Java.

Dusty

Offline

#9 2005-09-08 14:01:18

Euphoric Nightmare
Member
From: Kentucky
Registered: 2005-05-02
Posts: 283

Re: removing white space from a char[] (C)

Yeah, thats right.  I was going to learn c and python at the same time, but then i got so excited about c...well...

I can see what your saying about the python syntax...its very easy to read.


Dusty wrote:

I like Java.

Dusty

I haven't seen you say something like that in a very long time.

Offline

#10 2005-09-08 15:41:41

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: removing white space from a char[] (C)

Dusty wrote:

better to run a python instance and run string.trim()

But trim won't removing it from inside the string... you want replace(' ','');

#include <boost/string_algo/trim.hpp>
std::string s = "   i hate whitespace       ";
boost::trim(s);

s = "~~~~~some other crap~~~~~";
boost::trim_if(s, std::equals<char>('~'));

Offline

#11 2005-09-08 15:44:06

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: removing white space from a char[] (C)

Yeah, I'm a troll. :-D

Dusty

Offline

#12 2005-09-08 17:32:21

xerxes2
Member
From: Malmoe, Sweden
Registered: 2004-04-23
Posts: 1,249
Website

Re: removing white space from a char[] (C)

i haven't seen that trim thing dusty is talking about but replace() fix stuff like this,

>>> g = "     arch       linux     "
>>> g = g.replace(" ", "")
>>> print g
archlinux

arch + gentoo + initng + python = enlisy

Offline

#13 2005-09-08 17:55:59

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: removing white space from a char[] (C)

How embarrassing.

trim() is java syntax. Under python I was thinking of strip. It works as so:

>>> g = "     arch       linux     "
>>> g.strip()
'arch       linux'

Offline

#14 2005-09-08 18:16:02

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,893
Website

Re: removing white space from a char[] (C)

=>"            xersex2  is very cool ".tr(" ", "")
=>"xersex2isverycool"

Mr Green

Offline

#15 2005-09-10 21:11:34

xerxes2
Member
From: Malmoe, Sweden
Registered: 2004-04-23
Posts: 1,249
Website

Re: removing white space from a char[] (C)

whatlanguageisthatgreen?


arch + gentoo + initng + python = enlisy

Offline

#16 2005-09-10 21:15:41

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: removing white space from a char[] (C)

knowing Mr. Green, its probably lua, but could theoretically be ruby...

Or he made it up. :-D

Dusty

Offline

#17 2005-09-10 21:19:41

xerxes2
Member
From: Malmoe, Sweden
Registered: 2004-04-23
Posts: 1,249
Website

Re: removing white space from a char[] (C)

i tried lua and it didn't work sad

does'nt ruby work in a terminal?


arch + gentoo + initng + python = enlisy

Offline

#18 2005-09-11 01:55:49

dust
Member
Registered: 2005-06-04
Posts: 152
Website

Re: removing white space from a char[] (C)

looks like ruby big_smile


Writing stories for a machine.

Offline

#19 2005-09-11 17:36:00

xerxes2
Member
From: Malmoe, Sweden
Registered: 2004-04-23
Posts: 1,249
Website

Re: removing white space from a char[] (C)

a little bird whispered in my ear that rubys terminal is called 'irb' big_smile


arch + gentoo + initng + python = enlisy

Offline

#20 2005-09-11 17:54:51

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,893
Website

Re: removing white space from a char[] (C)

rofl .... lol


Mr Green

Offline

Board footer

Powered by FluxBB