Getting $$ to hold the concatenation of $1 & $2
I need to combine phrases together as a sentence and pass that as words. I have a yacc rule which states:
words : words WORD {
if($1 == NULL)
{
$$ = $2;
}
else
{
printf("\t$1 = %s\n",$1);
开发者_如何学编程 printf("\t$2 = %s\n",$2);
strBuffer[0]='\0';
strcat((char *)strBuffer,$1);
$$ = strcat((char *)strBuffer,$2);
printf("\t$$ = %s\n\n",$$);
}
}
char strBuffer[200] is a sufficiently large global array.
But when I run the parser, I get:
$1 = The G
$2 = nats and
$$ = nats and
What should I do so that both $1 & $2 make it into $$?
Try:
sprintf($$, "%s%s", $1, $2);
精彩评论