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
|
#include <string.h>
#include <stdlib.h>
void FinirBrin (char *TAB)
{
int lg = strlen (TAB);
if (lg > 3)
{
div_t d = div (lg, 3);
if (d.rem != 0)
{
TAB[3 * d.quot] = 0;
}
}
}
#if TEST
#include<stdio.h>
#include <assert.h>
static void test (char const in[], char const out[])
{
char *s = strdup (in);
assert (s != NULL);
FinirBrin (s);
assert (strcmp (s, out) == 0);
free (s);
}
int main (void)
{
test ("", "");
test ("a", "a");
test ("ab", "ab");
test ("abc", "abc");
test ("abcd", "abc");
test ("abcde", "abc");
test ("abcdef", "abcdef");
test ("abcdefg", "abcdef");
test ("abcdefgh", "abcdef");
puts ("P A S S E D");
return 0;
}
#endif |
Partager