C语言读取txt统计逗号或特定字符的个数

180it 2020-10-10 AM 1546℃ 0条
#include <stdio.h>
#include <dirent.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/time.h>
#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
using namespace std;

int main()
{
    FILE *fp;
    long sum  = 0;
    fp = fopen(filePath, "r");
    if (!fp)
        return false;
    
    while(!feof(fp))
    {
        if(fgetc(fp) == ',')
        {
            sum++;
        }
    }

 std::cout << "逗号个数是" << sum << std::endl;
}
支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

C语言读取txt统计逗号或特定字符的个数