c - Appending individual characters from string onto a char pointer -



c - Appending individual characters from string onto a char pointer -

i'm writing parser in c, , i've got code looks this:

char *consume_while(parser *self, int(*test)(char)) { char *result; while (eof(self) && (*test)(next_char(self))) { // append homecoming value function consumed_char(self) // onto "result" string defined above. } homecoming result; }

but i'm kinda new whole string manipulation aspect of c, how append character returned function consumed_char(self) result char pointer? i've seen people using strcat function, wont work takes 2 constant char pointers, i'm dealing char* , char. in java this:

result += consumed_char(self);

what's equivalent in c? :)

in c, strings not exist type, char arrays null-terminating character. means, assuming buffers big plenty , filled zeroes, can simple as:

result[(strlen(result)] = consumed_char(self);

if not, best bet utilize strcat , alter consumed_self function homecoming char *.

that beingness said, writing parser without basic understanding of c-style strings, is, least, quite ambitious.

c string pointers dynamic-allocation

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -