【发布时间】:2018-09-23 20:38:55
【问题描述】:
我目前正在尝试在缓冲区中提取子字符串。目标是通过空格和符号解析字符串以便稍后编译。我要解析的行是文件的第一行。
void append(char* s, char c)
{
int len = strlen(s);
s[len] = c;
s[len+1] = '\0';
}
int main(void){
char str[] = "program example(input, output);";
char *f = str;
char *b = str;
char token[10];
if(*f != '\0'){
while (*f != ' ')
{
append(token,*f);
f++;
}
f++;
printf("%s",token);
token[9] = '\0';
}
return 0;
}
我是否清除了错误的令牌字符串?代码只返回:
program
但它应该返回
program
example(input,
output);
【问题讨论】: