在c代码中.我有一个输入文件(称为in),格式为mad-lib,"我真的有<形容词>眼睛"(<>中没有空格)我想写一个bool函数,使用scanf来读取每个单词并返回true如果单词以'<'开头(也称为标记)我该怎么做呢?是的,我必须使用scanf.这是我现在所拥有的,但我不认为这是完全正确的,所以另一个问题是,我怎么知道我的功能是否正常工作.
/* istoken = returns true if word is a token */
bool istoken(char word[]) {
char first;
int firstindex;
while (1) {
scanf("%s", word);
first = word[MAX_LEN];
firstindex = (int)strlen(word);
if (first == '<') {
printf("The token is: %s\n", first);
return true; }
else {
return false; }
}
}
Run Code Online (Sandbox Code Playgroud)