Mercurial > hg > Applications > Grep
view c/regexParser/word.cc @ 161:584f32e18398 testcode
close
author | masa |
---|---|
date | Fri, 18 Dec 2015 19:17:02 +0900 |
parents | 5d29b6a1b50f |
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; }