Mercurial > hg > Members > masakoha > testcode
view c/getWord/word.c @ 113:ffef79514d3c pairPro
add getWord
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 23 Nov 2015 17:49:11 +0900 |
parents | |
children |
line wrap: on
line source
#include <ctype.h> #include <string.h> #include <stdio.h> #include <stdlib.h> unsigned char* getWord(unsigned char *string) { int wordSize = 0; while (isalnum(string[wordSize])) { wordSize++; } int allocateWordSize = wordSize + 1; unsigned char *word = (unsigned char*)malloc(sizeof(unsigned char)*allocateWordSize); strncpy((char*)word, (char*)string, allocateWordSize); word[wordSize] = '\0'; return word; }