• 编写一个删除c语言程序文件中所有的注释语句


    //删除c语言程序中所有的注释语句,要正确处理带引号的字符串与字符串常量
    #include <stdio.h>
    using namespace std;
    #define MAXLINE 1000
    void rcomment(int c); void in_comment(void); void deleteTail(void); FILE* fp; FILE* fp2;
    int main() { fp=fopen("C:\Users\Administrator\Desktop\leetcode.cpp","r"); fp2=fopen("C:\Users\Administrator\Desktop\out.txt","w"); bool deleteMutiline=false; char line[MAXLINE]; int c; while((c=getc(fp))!=EOF) rcomment(c); return 0; } void rcomment(int c){ int d; if(c=='/'){ if((d=getc(fp))=='*') in_comment(); else if (d=='/') deleteTail(); else { putc(c,fp2); putc(d,fp2); } }else putc(c,fp2); } void in_comment(void){ int c,d; c=getc(fp); d=getc(fp); while (c!='*'||d!='/') { c=d; d=getc(fp); } } void deleteTail(){ int c; c=getc(fp); while (c!=' ') { c=getc(fp); } putc(' ',fp2); }

    涉及标准库中的文件操作函数getc和putc,从文件中读单个字符,写单个字符到文件中。

    以及文件结构FILE。

    具体思路:

  • 相关阅读:
    天网管理系统
    NSCTF web200
    程序逻辑问题
    Once More
    Guess Next Session
    上传绕过
    加了料的报错注入
    C++ GET UTF-8网页编码转换
    Android学习笔记函数
    C++ 模拟虚拟键盘按键表
  • 原文地址:https://www.cnblogs.com/fightformylife/p/4314226.html
Copyright © 2020-2023  润新知