zoukankan      html  css  js  c++  java
  • WC.exe

    #include "stdio.h"

    #include "string.h"
    #include "stdlib.h"
     
    int charcalculate=0;
     
    int wordcalculate=0;
     
    int linecalculate=0;
     
    void calculate(char * file)
    {
        FILE * fp;
        char a;
        if((fp=fopen(file,"r"))==NULL)
        {
            printf("read file failed! ");
            exit(-1);
        }
        while(!feof(fp))
        {
            a=fgetc(fp);
            if(a!=' '&&a!=' '&&a!=' '&&a!=','&&a!='.'&&a!='!'&&a!=';'&&a!='=')
                charcalculate++;
            if(a==' '||a==' '||a==' '||a==','||a=='.'||a=='!'||a=='='||a==';')
                wordcalculate++;
            if(a==' '||a==' ')
                linecalculate++;
        }
        linecalculate++;
        charcalculate--;         
        fclose(fp);
    }
     
    int main(int argc, char* argv[])             
    {
        FILE *fp;
     
        calculate(argv[2]);
        while(1)
        {
            if((fp=fopen(argv[2],"r"))==NULL)
            {  
            printf("FileNull ");
            scanf("%s%s%s",argv[0],argv[1],argv[2]);
            continue;
            }
            else if(!strcmp(argv[1],"-c"))                 
                printf("File:%sCharNum:%d ",argv[2],charcalculate);
            else if(!strcmp(argv[1],"-w"))                  
                printf("File:%sWordNum:%d ",argv[2],wordcalculate);
            else if(!strcmp(argv[1],"-l"))                
                printf("File:%sLineNum:%d ",argv[2],linecalculate);
            else if(!strcmp(argv[1],"exit"))
            {
                printf("Exit! ");
                break;
            }
            else
                printf("NullPoint ");
            printf(" ");
            scanf("%s%s%s",argv[0],argv[1],argv[2]);
        }
        return 0;
         
    }
  • 相关阅读:
    准备使用 Office 365 中国版--邮箱迁移
    准备使用 Office 365 中国版--域名
    中国版的 Office 365
    了解 Office 365
    MySQL Database on Azure 参数设置
    MySQL Database on Azure 的用户名
    Android NOTE
    从源码看Android中sqlite是怎么通过cursorwindow读DB的
    一个由proguard与fastJson引起的血案
    【转载】淘宝架构框架发展史
  • 原文地址:https://www.cnblogs.com/Nein4444/p/7601255.html
Copyright © 2011-2022 走看看