Tutorial

/* hello world with the Vstr string API */

#define VSTR_COMPILE_INCLUDE 1
#include <vstr.h>
#include <errno.h>

int main(void)
{
  Vstr_base *s1 = NULL;

  if (!vstr_init())
    exit (EXIT_FAILURE);

  s1 = vstr_dup_cstr_buf(NULL, "Hello World\n");
  if (!s1)
    exit (EXIT_FAILURE);

  while (s1->len) /* assumes POSIX */
    if (!vstr_sc_write_fd(s1, 1, s1->len, 1, NULL))
    {
      if ((errno != EAGAIN) && (errno != EINTR))
        exit (EXIT_FAILURE);
    }

  vstr_free_base(s1);

  vstr_exit();

  exit (EXIT_SUCCESS);
}
  s1 = vstr_dup_cstr_buf(NULL, "Hello");
  if (!s1)
    exit (EXIT_FAILURE);

  vstr_add_rep_chr(s1, s1->len, 'W', 1);
  vstr_add_rep_chr(s1, s1->len, 'o', 1);

  vstr_add_buf(s1, s1->len, "rl", 1);

  vstr_add_cstr_buf(s1, s1->len, "d");

  VSTR_ADD_CSTR_BUF(s1, strlen("Hello"), " ");

James Antill
Last modified: Fri Aug 8 11:29:06 EDT 2003