帮我用C++简单的表示出来---急

[复制链接]
查看11 | 回复1 | 2008-6-18 23:47:39 | 显示全部楼层 |阅读模式
#include
#include
#define STOP '|'
int main(void)
{
char c;
char prev;
long n_chars = 0L;
int n_lines = 0;
int n_words = 0;
int p_lines = 0;
int inword = 0;
printf("Enter text to be analyzed( | to be quit):\n ");
prev = '\n';
while((c = getchar()) != STOP)
{
n_chars++;
if (c == '\n')
n_lines++;
if (!isspace(c) && !inword)
{
inword = 1;
n_words++;
}
if(isspace (c) && inword)
inword = 0;
prev = c;
}
if(prev != '\n')
p_lines = 1;
printf("characters = %ld,word = %d,line = %d,",
n_chars,n_words,n_lines);
printf("partial lines = %d\n",p_lines);
return 0;
}

回复

使用道具 举报

千问 | 2008-6-18 23:47:39 | 显示全部楼层
#include using namespace std;#define STOP '|' int main() { char c; char prev; long n_chars = 0L; int n_lines = 0; int n_words = 0; int p_lines = 0; int inword = 0; cout << "Enter text to be analyzed( | to be quit): " << endl;prev = '\n'; while((c = cin.get()) != STOP) { n_chars++; if
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行