view c/regexParser/word.cc @ 120:5d29b6a1b50f testcode

include Word in Node
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Thu, 26 Nov 2015 20:40:30 +0900
parents 31b0ba0050fa
children
line wrap: on
line source

#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "word.h"

int getWordLength(unsigned char* w){
    int i = 0;

    for (i=0;isalnum(w[i]);i++);

    return i;
}

WordPtr getWord(unsigned char *string) {

    WordPtr w = (WordPtr)malloc(sizeof(Word));

    int i = getWordLength(string);
    int wordLength;
    int allocateWordSize;

    wordLength = i;
    allocateWordSize = i+1;
    unsigned char *word = (unsigned char*)malloc(sizeof(unsigned char)*allocateWordSize);
    strncpy((char*)word, (char*)string, allocateWordSize);
    word[wordLength] = '\0';
    w->word = word;
    w->length = wordLength;
    return w;
}