1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define DBG 0
static void clean_string_r (char *s, int r, int w, int in_word, int first)
{
#if DBG
printf ("'%c' '%c' r=%2d w=%2d in_word=%d\n", s[r], s[w], r, w, in_word);
#endif
if (s[r] != 0)
{
if (in_word)
{
if (isspace (s[r]))
{
clean_string_r (s, r + 1, w, !in_word, first);
}
else
{
s[w] = s[r];
clean_string_r (s, r + 1, w + 1, in_word, first);
}
}
else
{
if (isspace (s[r]))
{
clean_string_r (s, r + 1, w, in_word, first);
}
else
{
if (first)
{
s[w] = s[r];
clean_string_r (s, r + 1, w + 1, !in_word, !first);
}
else
{
s[w] = ' ';
s[w + 1] = s[r];
clean_string_r (s, r + 1, w + 2, !in_word, first);
}
}
}
}
else
{
s[w] = 0;
}
}
static void clean_string (char *s)
{
clean_string_r (s, 0, 0, s[0] != ' ', 1);
}
int main (int argc, char **argv)
{
char s[] = " forum\tDeveloppez.com ";
printf ("'%s'\n", s);
clean_string (s);
printf ("'%s'\n", s);
if (strcmp (s, "forum Developpez.com") == 0)
{
printf ("\nP A S S E D\n");
}
return 0;
} |
Partager