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
|
#include <string.h>
void ReverseString (char const str[], char res[])
{
int const len = strlen (str);
int i = 0;
if (len > 0)
{
do
{
res[len - 1 - i] = str[i];
i++;
}
while (i < len);
}
res[i] = '\0';
}
/* test unitaire */
#include <stdio.h>
#include <assert.h>
int main (void)
{
{
char result[] = "?????";
ReverseString ("a" + 1, result);
assert (strcmp ("", result) == 0);
}
{
char result[] = "?????";
ReverseString ("ab" + 1, result);
assert (strcmp ("b", result) == 0);
}
{
char result[] = "?????";
ReverseString ("", result);
assert (strcmp ("", result) == 0);
}
{
char result[] = "?????";
ReverseString ("a", result);
assert (strcmp ("a", result) == 0);
}
{
char result[] = "?????";
ReverseString ("ab", result);
assert (strcmp ("ba", result) == 0);
}
{
char result[] = "?????";
ReverseString ("abc", result);
assert (strcmp ("cba", result) == 0);
}
{
char result[] = "?????";
ReverseString ("ab\0c", result);
assert (strcmp ("ba", result) == 0);
}
puts ("P A S S E D");
return 0;
} |
Partager