[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  Strip spaces
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Strip spaces

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Zeno   USA  (2,871 posts)  [Biography] bio
Date Mon 25 Jul 2005 04:29 PM (UTC)
Message
Just a random question. Is there a function that strips the spaces from a string? I'm asking in Smaug just in case none exists in *nix and Smaug has its own unique function to do it.

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Reply #1 on Tue 26 Jul 2005 11:32 PM (UTC)
Message
These is no system command that I know of, but I have one of my own:

char     *smash_space(const char *str)
{
        static char ret[MAX_STRING_LENGTH];
        char     *retptr;

        retptr = ret;
        for (; *str != '\0'; str++)
        {
                if (*str == ' ')
                        continue;
                else
                {
                        *retptr = *str;
                        retptr++;
                }
        }
        *retptr = '\0';
        return ret;
}

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

Posted by Zeno   USA  (2,871 posts)  [Biography] bio
Date Reply #2 on Tue 26 Jul 2005 11:36 PM (UTC)
Message
Hm, I'll try it out thanks.

A quick side question. When I say "linux function" am I incorrect? Should I be saying "C function"? I'm not sure I totally understand then. Would that mean the function in Windows in C to move a window is the same function as one on linux?

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Nick Cash   USA  (626 posts)  [Biography] bio
Date Reply #3 on Tue 26 Jul 2005 11:56 PM (UTC)
Message
Quote:

A quick side question. When I say "linux function" am I incorrect? Should I be saying "C function"? I'm not sure I totally understand then. Would that mean the function in Windows in C to move a window is the same function as one on linux?


I guess technically you should be saying "ANSI C". While the systems have evolved and differ a bit, generally anything in the ANSI C standard will be found cross platform (such as strcmp, etc).

The Win32 API would definitely not be the same as a graphical API on linux. While the function names might be similar, they arent part of the standard, and are written specifically for their platform.

Of course you may find API's like SDL that are cross platform and control windows and various things, in which case you would be correct, as all of the function calls would be the same for any platform.

~Nick Cash
http://www.nick-cash.com
[Go to top] top

Posted by Zeno   USA  (2,871 posts)  [Biography] bio
Date Reply #4 on Wed 27 Jul 2005 04:59 AM (UTC)
Message
Hmm if I'm using arg1 which is [MAX_STRING_LENGTH], how would I replace the string?
arg1 = smash_space(arg1)

Obviously doesn't work because they aren't the same type.

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Reply #5 on Wed 27 Jul 2005 05:09 AM (UTC)
Message
No, it returns a character pointer, so you need to store it into a character pointer variable.

char *arg;

sprintf(arg, "Before: %s\nAfter: %s", string, smash_space(string));

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

Posted by Zeno   USA  (2,871 posts)  [Biography] bio
Date Reply #6 on Wed 27 Jul 2005 05:13 AM (UTC)
Message
But won't that cause incompatibles elsewhere? I have this already:
    sprintf( cfilename, "%s.cln", strlower( arg ));

Could I now just:
sprintf( cfilename, "%s", strip_space(cfilename);

Or would I need to change it to a pointer still?

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Reply #7 on Wed 27 Jul 2005 05:24 AM (UTC)
Message
Well, if you wanted to lower everything, you could use this:

    sprintf( cfilename, "%s.cln", strip_space(strlower( arg )));


Since strlower returns a character pointer, and the argument for strip_space is a character pointer, no incompatabilities.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


5,444 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]