1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <stdlib.h>
#include <stdio.h>
#include "str.h"
void
clearStr(struct Str *str)
{
*(str->end = str->cstr) = 0;
}
void
appendCharToStr(struct Str *str, char c)
{
// check if another character and 0 byte fits into string
if (str->end - str->cstr + 2 > sizeof(str->cstr)) {
fprintf(stderr, "error in appendCharToStr: string too long\n");
exit(1);
}
*str->end++ = c;
*str->end = 0;
}
|