[TynesideLUG] Test driven development
Ian Bruntlett
ian.bruntlett at gmail.com
Sat Sep 28 17:02:25 UTC 2019
Hi,
I've just used test driven development in C! Here is a function that
removes preceding whitespace from a string..
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define TEST_MAX (100)
void ltrimcpy(char *dest, char *src)
{
char *first_ok;
for (first_ok=src;
isspace(*first_ok);
++first_ok)
;
strcpy(dest,first_ok); // possibly use strncpy?
}
void test_ltrimcpy(char *test_argument)
{
char test_result[TEST_MAX];
ltrimcpy(test_result, test_argument);
printf("argument : '%s' result : '%s'\n", test_argument, test_result);
}
int main(void)
{
test_ltrimcpy(" Hello ");
test_ltrimcpy("Hello ");
test_ltrimcpy("");
return 0;
}
--
-- ACCU - Professionalism in programming - http://www.accu.org
-- My writing - https://sites.google.com/site/ianbruntlett/
-- Free Software page -
https://sites.google.com/site/ianbruntlett/home/free-software
More information about the Tyneside
mailing list