如何用C实现
来源:百度知道 编辑:UC知道 时间:2024/05/10 21:52:12
有一个名为part.dat的文件,其内容是:
id affiliation group
012142-1-A UNE Parallel-1
012312-3-A USQ Parallel-2
012341-1-B UNE Fuzzy-1/2
如何用C实现读取文件内容,去掉头行后输出字母,并计算大写字母数与小写字母数,出输结果如下:
AUNEParallelAUSQParallelBUNEFuzzy
15 18
并把结果保存到另一文件里.
急!
答案理想,另有加分
id affiliation group
012142-1-A UNE Parallel-1
012312-3-A USQ Parallel-2
012341-1-B UNE Fuzzy-1/2
如何用C实现读取文件内容,去掉头行后输出字母,并计算大写字母数与小写字母数,出输结果如下:
AUNEParallelAUSQParallelBUNEFuzzy
15 18
并把结果保存到另一文件里.
急!
答案理想,另有加分
我用C++写了个,C我不太熟...
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main()
{
fstream fstrm("part.dat");
if(!fstrm)
throw;
string store;
getline(fstrm, store);
store.clear();
char c;
int upper = 0;
int lower = 0;
while(fstrm.get(c))
{
if(!(c >= 97 && c <= 122 || c >= 65 && c <= 90))
continue;
if(c >= 97 && c <= 122)
++lower;
else if(c >= 65 && c <= 90)
++upper;
store.push_back(c);
}
fstrm.close();
fstrm.clear();
fstrm.open("out.dat", ios_base::trunc | ios_base::out);
if(!fstrm)
throw;
cout << store << endl;
fstrm << store << endl;
cout << upper << ' ' << lower << endl;
fstrm &l