comparison 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
comparison
equal deleted inserted replaced
112:ec485345daf9 113:ffef79514d3c
1 #include <ctype.h>
2 #include <string.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5
6 unsigned char* getWord(unsigned char *string) {
7 int wordSize = 0;
8 while (isalnum(string[wordSize])) {
9 wordSize++;
10 }
11
12 int allocateWordSize = wordSize + 1;
13 unsigned char *word = (unsigned char*)malloc(sizeof(unsigned char)*allocateWordSize);
14 strncpy((char*)word, (char*)string, allocateWordSize);
15 word[wordSize] = '\0';
16 return word;
17 }