Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
➜ SMAUG
➜ SMAUG coding
➜ Strip spaces
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Zeno
USA (2,871 posts) 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 | Top |
|
Posted by
| Greven
Canada (835 posts) 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 | Top |
|
Posted by
| Zeno
USA (2,871 posts) 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 | Top |
|
Posted by
| Nick Cash
USA (626 posts) 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 | Top |
|
Posted by
| Zeno
USA (2,871 posts) 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?
Obviously doesn't work because they aren't the same type. |
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | Top |
|
Posted by
| Greven
Canada (835 posts) 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 | Top |
|
Posted by
| Zeno
USA (2,871 posts) 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 | Top |
|
Posted by
| Greven
Canada (835 posts) 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 | 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.
20,460 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top