#include <mecab.h>
#include <stdio.h>
#include <stdlib.h>

int main (int argc, char **argv)
{
   char p[] = "太郎は次郎が持っている本を花子に渡した。";
   mecab_t *c = mecab_new (argc, argv);
   mecab_node_t *n;
   char *r;

   if (!c) {
      fprintf (stderr, "Exception: [%s]\n", mecab_strerror (0));
      return -1;
   }

   r = mecab_sparse_tostr (c, p);
   

   if (!r) {
      fprintf (stderr, "Exception: [%s]\n", mecab_strerror (c));
      return -1;
   }
   
   fprintf (stdout, "%s\n", r);

   n = mecab_sparse_tonode (c, p);

   if (!n) {
      fprintf (stderr, "Exception: [%s]\n", mecab_strerror (c));
      return -1;
   }
   
   for (;  n ; n = n->next) {
      fwrite (n->surface, n->length, sizeof (char), stdout);
      fprintf (stdout, "\t%s\n",n->feature);
   }
   fprintf (stdout, "EOS\n");    

   mecab_destroy (c);

   return 0;
} 
