算上';s在c中表示为两个单词 #包括 #包括 #包括 int main() { 无符号长c; 无符号长线; 无符号长单词; char ch; c=0; 直线=0; 字=0; printf(“请输入文本:\n”); 而((ch=getchar())!=EOF) { C++ 如果(ch='\n') { line++; } 如果(ch=''| | ch='\n') { word++; } } printf(“%lu%lu%lu\n”,c,字,行); 返回0; }
现在,我的程序可以正常工作,并且可以正确计算字符、单词和行数。但是对于像这样的单词,程序将其计算为1个单词,我希望它计算为2个单词。我需要添加什么来解释这一点?关于“it’s”、“let’s”和“Jim’s”呢?对于一个具有多个连续空格的输入,您的程序会给出多少字数,这对您的目的正确吗?那么,“如何在字数计算算法中检测并计算两个词的缩略?”可以总结一下你的问题吗?假设他只想把连词算作两个词,“吉姆家的聚会”将返回一个不正确的字数。算上';s在c中表示为两个单词 #包括 #包括 #包括 int main() { 无符号长c; 无符号长线; 无符号长单词; char ch; c=0; 直线=0; 字=0; printf(“请输入文本:\n”); 而((ch=getchar())!=EOF) { C++ 如果(ch='\n') { line++; } 如果(ch=''| | ch='\n') { word++; } } printf(“%lu%lu%lu\n”,c,字,行); 返回0; },c,counting,words,apostrophe,C,Counting,Words,Apostrophe,现在,我的程序可以正常工作,并且可以正确计算字符、单词和行数。但是对于像这样的单词,程序将其计算为1个单词,我希望它计算为2个单词。我需要添加什么来解释这一点?关于“it’s”、“let’s”和“Jim’s”呢?对于一个具有多个连续空格的输入,您的程序会给出多少字数,这对您的目的正确吗?那么,“如何在字数计算算法中检测并计算两个词的缩略?”可以总结一下你的问题吗?假设他只想把连词算作两个词,“吉姆家的聚会”将返回一个不正确的字数。 #include <stdlib.h> #inclu
#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
int main()
{
unsigned long c;
unsigned long line;
unsigned long word;
char ch;
c = 0;
line = 0;
word = 0;
printf("Please enter text:\n");
while((ch = getchar()) != EOF)
{
c ++;
if (ch == '\n')
{
line ++;
}
if (ch == ' ' || ch == '\n')
{
word ++;
}
}
printf( "%lu %lu %lu\n", c, word, line );
return 0;
}
if(ch =='\'' || ch == ' ' || ch == '\n')
{
word++;
}