c - 用于计算文件中“int”运算符的有限状态机 - 不起作用
问题描述
我有一个制作有限状态机的项目。程序必须打开文件并分析它的“Int”和“float”语句,并将结果保存到一个新文件中。下面是有限状态机的代码:
typedef enum sta_word{None, In_int, End_int} s_INT;
s_INT ComputeInt(int c, char* INT, s_INT status);
s_INT ComputeInt(int c, char* INT, s_INT status)
{
static int ind = 0;
char ch = c;
if (status == End_int)
{
status = None;
ind = 0;
}
switch (status)
{
case None:
if (ch!='int')
{
status = In_int;
INT[ind++] = c;
}break;
case In_int:
if (ch=='int')
{
status = End_int;
INT[ind] = 0;
}
else
{
INT[ind++] = c;
}
break;
}
return status;
}
也就是计数函数:(FILE* fp 是打开文件进行读取)
int CountINT(FILE* fp)
{
FILE* file;
file = fopen("count.txt", "w");
if (file == NULL)
{
perror("ERROR: ");
}
int br_INT = 0;
int c;
s_INT status = None;
char INT[256];
rewind(fp);
do
{
c = fgetc(fp);
status = ComputeInt(c, INT, status);
if (status == End_int)
{
br_INT++;
}
} while (c != EOF);
fprintf(file, "\n\ncompute %d INT Operators into file", br_INT);
return 0;
}
但是当我打开文件进行写入时,什么都没有。
解决方案
推荐阅读
- python-3.x - 令牌必须是字节,'List' 不可调用?P3.7
- angular - JS Fiddle 中的 Angular 4 - 无法解决依赖问题
- sql - 在 Hive SQL 中 - 加入没有 UDF 的间隔
- java - 刷新当前片段而不留下片段新/更改的数据
- amazon-web-services - 管理连接到 Auto Scaling 组的 rds
- sql - Oracle rownum 在范围内
- python - 如何为 Flask 的 render_template() 优化模板
- wso2 - 在 JWT 授权中,如何将 JWT 令牌中包含的授权声明与与交换的访问令牌关联的范围相关联?
- mongodb - 几个小时后,聚合因网络错误而失败
- java - 如何在 Gradle 多项目构建中配置每个 Kotlin 项目?