免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1091 | 回复: 4
打印 上一主题 下一主题

[C++] 這題c++要怎樣做? 請教教小弟>﹏< [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-01-02 20:23 |只看该作者 |倒序浏览
"You will write a program that reads in a file and counts the number
of lines, words, and characters. Your program should ask the user to input a filename.
Open the file and report an error if the file does not exist or cannot be opened for some
other reason.
Then read in the contents of the file and count the number of lines, words, and characters
in the file. Also print additional information about the file, such as the longest and
shortest words, and longest and shortest lines. For simplicity, we define a word to be one
or more characters ending with white space (a space, tab, carriage return, etc.). Functions
for checking the types of characters can be found in the ctype.h header file, so you want
to include this header file in your program."

我不會做>;﹏<

论坛徽章:
0
2 [报告]
发表于 2005-01-02 20:27 |只看该作者

這題c++要怎樣做? 請教教小弟>﹏<

#include <iostream.h>;
#include <stdlib.h>;
#include <fstream.h>;
#include <string.h>;

int main()
{
char infile[100], buffer[100], *pch, *pch1, ch;
int total_line=0, total_word=0, total_char=0, i=0;

cout<<"Enter input file name:";
cin>;>;infile;
ifstream in(infile);
if(!in)
cout<<"Error open file...";

else

while(in.getline(infile,100, '\\n'))
{
total_line++;

if (pch = strtok (infile," ,."){

while (pch != NULL) {
pch = strtok (NULL, " ,.";
total_word++;
}//while (pch != NULL)
}
}//while

cout<<"It has "<<total_line<<" lines"<<endl;
cout<<"It has "<<total_word<<" words"<<endl;
cout<<"It has "<<total_char<<" characters"<<endl;

in.close();

system("AUSE";
return 0;
}//main

我還欠甚麼?

论坛徽章:
0
3 [报告]
发表于 2005-01-03 12:53 |只看该作者

這題c++要怎樣做? 請教教小弟>﹏<

PUSH

论坛徽章:
0
4 [报告]
发表于 2005-01-04 10:01 |只看该作者

這題c++要怎樣做? 請教教小弟>﹏<

int main(int argc,char *argv[])
{
   if(argc!=2)
      exit();
   if((fp=fopen(*argv[1],"r")==NULL)
   {printf("read file %s failed!",*argv[1]);exit();}
   else
   {
      ……
   }
   
}

论坛徽章:
1
15-16赛季CBA联赛之四川
日期:2016-02-15 17:12:32
5 [报告]
发表于 2005-01-04 10:46 |只看该作者

這題c++要怎樣做? 請教教小弟>﹏<

argv[1]不需要*号
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP