c - 删除评论的程序,只有一个文件
问题描述
while((current = fgetc(file_with_comments)) != EOF){
exit_flag = false;
switch(current){
case '/':
if((current = fgetc(file_with_comments)) == '*'){
do{
if((current = fgetc(file_with_comments)) == '*'){
if((current = fgetc(file_with_comments)) == '/'){
exit_flag = true;
}
}
}while(exit_flag == false);
}
if(exit_flag == false){
array_of_char[index] = '/';
index++;
}
break;
case '*':
printf("does u go in here\n");
break;
default:
array_of_char[index] = current;
index++;
}
}
所以我正在尝试构建这个从 .c 文件中删除注释的程序(不是单行注释所以 // )
我尝试了很多不同的方法,这是我最新的也是迄今为止最成功的方法。但是,如果它应该起作用,它不适用于某些事情。
例如,如果我将其用于输入
/**** This is a comment with a bunch of stars in it ****/
//* This is a comment immediately after a slash */
/* This is a comment immediately before a slash *//
除了最后一个'/',输出将是正确的,程序将删除它,我不知道为什么。感谢您的帮助!
编辑:刚刚意识到我在代码中留下了'*'的情况,这可以忽略,因为我没有使用它。
解决方案
推荐阅读
- c# - 带有 .Net Core SDK 3.0 预览的错误 Visual Studio 代码和 Omnisharp 扩展
- python - 在回归中使用 group by 在 python 中定义 x 和 y 值
- sql - SQL - 拆分字符串多个值,多个值
- azure - 天蓝色 SQL 数据库对共同管理员不可见
- javascript - 单击时无法显示日历 - 没有 JS 错误
- tfs - TFS 2015 到 2018 升级后脚本不起作用
- sql-server - 将 Excel 转换为 CSV,然后使用将这些数据导出到 sql 表
- angular - 垫排序不适用于角垫表
- python - 如何重命名类似于名称的数字的数据框列?
- angular - ./src/main/webapp/app/app.main.ts中的Jhipster webpack生产错误,找不到模块:错误:无法解析'./app.module.ngfactory'