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