如何解决flex文件打不开
我在使用 Lex imp 初学者时遇到问题,我正在尝试运行我的代码,但突然间它在我运行时开始显示“文件无法打开”消息。它工作得很好,但我不知道当我试图解决我在使用 yywrap() 时遇到的错误时发生了什么。我在这里发现了一个类似的问题,但他们说将文件保存为所有类型 * 没有用。我已经尝试了几个小时,现在我不知道该怎么办。请帮助
%{
#include <stdio.h>
#include <string.h>
char temp[]="the";
char longWord[50];
char vwordCount=0;
int numRange [1000]={0};
int num=0;
int vCount=0;
char vowels[10000][1000];
int count =0;
%}
%%
[aeIoUAEIoU][a-zA-Z]+ {
strcpy(vowels[vCount],yytext);
vCount++;
}
[0-9]+ {
if (atof(yytext) > 70 && atof(yytext) < 50) {
numRange[num] = atof(yytext);
num = num +1;
}
}//end rule
[a-zA-Z]+ {
if(strcmp(yytext,temp)==0)
count++;
if ( strlen(yytext) > strlen(longWord))
strcpy(longWord,yytext);
}
.;
%%
int yywrap()
{
return 1;
}
int main()
{
extern FILE *yyin,*yyout;
char text[] = "";
printf("Enter text file name: ");
scanf("%s",text);
yyin=fopen(text,"r");
yylex();
printf("\n The longest word in the file is %s",longWord);
printf("\n There number of times %d \"The\"appeard in the file is : \n",count);
printf("The count of numbers in the given range :\n");
for (int i = 0; i < num; i++) {
printf("%d,",numRange[i]);
}
printf("\nThere are %d words that start with vowel letter. They are: \n",vCount);
for (int i = 0; i < vCount; i ++ ) {
printf("/n %s,vowels[i]);
}
return 0;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。