【发布时间】:2018-11-29 01:44:17
【问题描述】:
我试图在 Yacc 中打印一个带有 char 指针的字符串,但是当我尝试时它给了我一个段错误。在 lex 文件中它看起来像:
\"([^"]|\\\")*\" {yylval.s = strdup(yytext); yycolumn += yyleng; return(STRINGnumber);}
我收到的字符串文字看起来像:
//Used to store the string literal
char * s;
//To store it I call
strcpy(s, $1); //Where $1 is the string literal
每当我打电话时
printf("%s", s);
它给了我一个分段错误。为什么会这样做,如何解决?
【问题讨论】: