zoukankan      html  css  js  c++  java
  • 统计文本文档

    // p.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"
    #include<stdio.h>
    #include<string.h>
    int n_char(FILE *fp)
    { int num = 0;
    char s[20];
    while(!feof(fp))
    { fscanf(fp, "%s", s); //读取字符串 num += strlen(s); //叠加字符数
    }
    printf("字符数(不计空格和回车)有%d个 ",num);
    rewind(fp); //绕回文件指针
    return num;
    }
    int n_world(FILE *fp)
    {
    char s[20];
    int n = 0, num = 0;
    while(!feof(fp))
    {
    if(fscanf(fp, "%s", s) && !(s[0] >='0' && s[0] <='9'))
    n++;
    else
    num++;
    }
    printf("单词数有%d个,数字有%d个 ",n,num);
    rewind(fp);
    return n;
    }
    int n_row(FILE *fp)
    {

    int n = 1;
    char ch;
    while(!feof(fp))
    {
    if((ch = fgetc(fp) == ' ')) n++;
    }
    printf("有%d行 ", n); rewind(fp);
    return n;
    }
    void main()
    {
    FILE *fp;
    fp = fopen("d:\aaa.txt", "r"); //打开文件
    n_char(fp);
    n_world(fp);
    n_row(fp);
    fclose(fp);
    }

    运行测试

  • 相关阅读:
    线性基学习笔记
    内网靶机-抓取票据
    域渗透
    flex元素的使用
    webpack 基本使用
    ES模块的导入
    作用域插槽
    具名插槽的使用
    slot插槽的基本使用
    vue中父子组件的访问方式
  • 原文地址:https://www.cnblogs.com/jingaaaaa/p/5561148.html
Copyright © 2011-2022 走看看