gpt4 book ai didi

c - 在 C 中循环遍历输入文件行时出现问题

转载 作者:太空宇宙 更新时间:2023-11-04 08:28:06 25 4
gpt4 key购买 nike

<分区>

我正在尝试通过我的输入文件的不同行来运行我的标记化函数。

void
tokenize(FILE *src, char* buffer)
{

fprintf(stdout,"%s\n", buffer);
int i = 0;
while ( buffer[i] != '\n'){
if(buffer[i] == ' '){
i++ ;
}else if (buffer[i]=='+'){
fprintf(stdout,"+ Addition operator\n");
i++;
}else if (buffer[i]=='-'){
fprintf(stdout,"- Subtraction operator\n");
i++;
}else if (buffer[i]=='*'){
fprintf(stdout,"* Multiplication operator\n");
i++;
}else if (buffer[i]=='/'){
fprintf(stdout,"- Division operator\n");
i++;
}else if (buffer[i]=='^'){
fprintf(stdout,"- Exponentiation operator\n");
i++;
}else if( buffer[i]== '>'){
if(buffer[i+=1] == '='){
fprintf(stdout, ">= Comparison Operator\n");
i+=2;
}else{
fprintf(stdout,"> Comparison Operator\n");
i+=1;
}
}else if( buffer[i]== '<'){
if(buffer[i+=1] == '='){
fprintf(stdout, "<= Comparison Operator\n");
i+=2;
}else{
fprintf(stdout,"< Comparison Operator\n");
i+=1;
}
}else if (isdigit((int)buffer[i])){
fprintf(stdout, "%c Simple Numeral\n",buffer[i]);
i++;
}else if (buffer[i] == ')'){
i++;
}else if (buffer[i] == '('){
i++;
}
}
}

int
main(int argc, const char* argv[])
{

FILE* src = input_from_args(argc, argv);
char str[80];
while(fgets(str, 80, src) && fgetc(src)!=EOF){
tokenize(src, str);
}

return 0;
}

根据以前的经验,我觉得自己走在正确的轨道上。通过输入文件进行循环总是让我感到困惑。到目前为止,它只经过第一行。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com