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
| char *str_strip (const char *string)
{
char *strip = NULL;
if (string != NULL)
{
strip = malloc (sizeof (*strip) * (strlen (string) + 1));
if (strip != NULL)
{
int i, j;
int ps = 0;
for (i = 0, j = 0; string[i]; i++)
{
if (string[i] == ' ')
{
/*if (ps == 0)
{
strip[j] = string[i];
ps = 1;
j++;
}*/
}
else
{
strip[j] = string[i];
ps = 0;
j++;
}
}
printf("j %d\n",j);
strip[j]='\0';
}
else
{
fprintf (stderr, "Memoire insuffisante\n");
exit (EXIT_FAILURE);
}
}
return strip;
} |
Partager