| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Snippets ini.c |
From: Kurt Kuzba
KK> if (string || *string)
Yes... But not quite right, is it? I'm sure you meant to post
a fully operational version, which is more like this:
/*_|_| notrail.c
_|_|_| Public Domain : Kurt Kuzba : Friday, September 19, 2003
_|_|_| Simple routine to strip trailing spaces in one pass.
_|_|_| No guarantee or warrantee is given or implied.
_|_|*/
#include
#include
#define NUL 0;
static char *notrail(char *string)
{
int space = 0, iterator = 0;
if (string && *string)
{
for(; *(string + iterator); iterator++)
if(!isspace(*(string + iterator))) space = iterator;
if(space != iterator) *(string + space + 1) = NUL;
}
return string;
}
int main (void)
{
char buf[32],
*test[10] = {"trailing test ", "test",
"trailing * ",
"foo0", "foo1 ", "foo2 ", "foo3
", "foo4 ",
" penultimate", NULL};
int iterator;
for(iterator = 0; iterator < 10; iterator++)
{
sprintf(buf, "%s", test[iterator]);
notrail(buf);
printf("*%s*\n", buf);
}
fgets(buf, 16, stdin);
return 0;
}
/*_|_| end notrail.c
_|_|*/
While the error is indefensible, I'm certain that with a bit
more practice, you will stop making silly errors some day...
Given your propensity to act in haste and without giving full
consideration to what you are about, however, perhaps not!
> kkuzba{at}centurytel.net http://home.centurytel.net/kkuzba
> But it has long been said, 'Oft evil will shall evil mar.'
--- SoupGate-Win32 v1.05
* Origin: kkuzba{at}centurytel.net (2:292/516.666)SEEN-BY: 633/267 270 @PATH: 292/516 854 140/1 106/2000 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.