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

来源:百度知道 编辑:UC知道 时间:2024/05/29 04:32:14
#include<stdio.h>
#include<ctype.h>
#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;

}

#include <iostream>
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 (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;
cout << "characters = " << n_chars << "," << "word = " << n_words << "," << "line = " << n_lines << ","
<< "partial lines = " <<