爱情丛林法则pdf:1、从键盘读入一行最大包含255个字符的句子(句子中没有标点,单词间以一个或多个空格/TAB分隔)。
来源:百度文库 编辑:神马品牌网 时间:2024/04/29 22:27:00
/*
This program is designed to collect all vowels in an input sentence, and to print the sentence with all of the words
in an inversed order. Also words in the sentence are counted.
This program has some errors and some unfinished parts, please correct the errors and complete the program.
Besides, please explain the functions of two indicated parts (your answer should be added in the program as comments).
Please publish your results no later than 20:40.
*/
#include <stdio.h>
#include <stdlib.h>
int collectvowels(char *src, char *vow, char *wrd[]);
int isvowel(char ch);
void main()
{
/*At least two errors in this function. Please correct them.*/
/*本函数中至少有两处错误,请修改*/
char str[256], vowels[256];
char *words[80], cnt;
printf("Input a sentence: ");
scanf("%s", str);
cnt=collectvowels(str, vowels, *words);
printf("Vowels in the inputed sentence are: %s\n", vowels);
printf("The sentence contains %d words\n", cnt);
printf("And the inversed sentence is: ");
while(cnt--)
printf("%s ", words[cnt]);
printf("\n");
}
int collectvowels(char src[], char vow[], char *wrd[])
{
/*Express correspondence variants in the form of pointers instead of arrays */
/*把本函数中的数组表示形式改成指针的形式*/
int i=0, j=0, k=0, cnt=0;
char tmp[80];
while(src[i]){
if (src[i]==' ' || src[i]=='\t' || src[i+1]=='\0'){
if (src[i+1]=='\0')
tmp[k++]=src[i];
else{
/*Explain the functions of the following two statements.*/
/*下面两行语句所起的作用是?分别说明。*/
while (src[++i]==' ' || src[i]=='\t');
i--;
}
/*A statement may be needed here*/
/*此处需要一条语句*/
wrd[cnt]=malloc(k*sizeof(char));
/*Explain the functions of the loop statement.*/
/*这个循环的作用是?*/
do{
*(wrd[cnt]+k)=tmp[k];
}while(k--);
k++;
cnt++;
}
else
/*A statement may be needed here*/
/*此处需要一条语句*/
/*A conditional expression is required here*/
/*在括号中填入条件表达式*/
if ( )
vow[j++]=src[i];
/*A statement may be needed here*/
/*此处需要一条语句*/
}
/*Statements may be needed here*/
/*此处需要一或多条语句*/
}
int isvowel(char ch)
{
char vowels[]="aeiouAEIOU";
int i=0;
/*Complete this function. If ch is a vowel, the function returns 1, else returns 0. No switch statement please.*/
/*完成该函数。返回值为1表示ch为元音字母,为0则是其它字符。不要用switch语句啊:-)*/
}
1、从键盘读入一行最大包含255个字符的句子(句子中没有标点,单词间以一个或多个空格/TAB分隔)。
2、将句中的所有元音字母存入一个新的串。
3、统计单词个数。
4、将单词分别存入另一数组,并按反序输出(单词间仅以一个空格为分隔符)。
如输入:
Uh This Is A Test To Collect Vowels In The Sentence And Count The Words And Print The Sentence In Inversed Order
则输出为:
Input a sentence: Vowels in the inputed sentence are: UiIAeooeoeIeeeeAoueoAieeeeIIeeOe
The sentence contains 22 words
And the inversed sentence is: Order Inversed In Sentence The Print And Words The Count And Sentence The In Vowels Collect To Test A Is This Uh
This program is designed to collect all vowels in an input sentence, and to print the sentence with all of the words
in an inversed order. Also words in the sentence are counted.
This program has some errors and some unfinished parts, please correct the errors and complete the program.
Besides, please explain the functions of two indicated parts (your answer should be added in the program as comments).
Please publish your results no later than 20:40.
*/
#include <stdio.h>
#include <stdlib.h>
int collectvowels(char *src, char *vow, char *wrd[]);
int isvowel(char ch);
void main()
{
/*At least two errors in this function. Please correct them.*/
/*本函数中至少有两处错误,请修改*/
char str[256], vowels[256];
char *words[80], cnt;
printf("Input a sentence: ");
scanf("%s", str);
cnt=collectvowels(str, vowels, *words);
printf("Vowels in the inputed sentence are: %s\n", vowels);
printf("The sentence contains %d words\n", cnt);
printf("And the inversed sentence is: ");
while(cnt--)
printf("%s ", words[cnt]);
printf("\n");
}
int collectvowels(char src[], char vow[], char *wrd[])
{
/*Express correspondence variants in the form of pointers instead of arrays */
/*把本函数中的数组表示形式改成指针的形式*/
int i=0, j=0, k=0, cnt=0;
char tmp[80];
while(src[i]){
if (src[i]==' ' || src[i]=='\t' || src[i+1]=='\0'){
if (src[i+1]=='\0')
tmp[k++]=src[i];
else{
/*Explain the functions of the following two statements.*/
/*下面两行语句所起的作用是?分别说明。*/
while (src[++i]==' ' || src[i]=='\t');
i--;
}
/*A statement may be needed here*/
/*此处需要一条语句*/
wrd[cnt]=malloc(k*sizeof(char));
/*Explain the functions of the loop statement.*/
/*这个循环的作用是?*/
do{
*(wrd[cnt]+k)=tmp[k];
}while(k--);
k++;
cnt++;
}
else
/*A statement may be needed here*/
/*此处需要一条语句*/
/*A conditional expression is required here*/
/*在括号中填入条件表达式*/
if ( )
vow[j++]=src[i];
/*A statement may be needed here*/
/*此处需要一条语句*/
}
/*Statements may be needed here*/
/*此处需要一或多条语句*/
}
int isvowel(char ch)
{
char vowels[]="aeiouAEIOU";
int i=0;
/*Complete this function. If ch is a vowel, the function returns 1, else returns 0. No switch statement please.*/
/*完成该函数。返回值为1表示ch为元音字母,为0则是其它字符。不要用switch语句啊:-)*/
}
1、从键盘读入一行最大包含255个字符的句子(句子中没有标点,单词间以一个或多个空格/TAB分隔)。
2、将句中的所有元音字母存入一个新的串。
3、统计单词个数。
4、将单词分别存入另一数组,并按反序输出(单词间仅以一个空格为分隔符)。
如输入:
Uh This Is A Test To Collect Vowels In The Sentence And Count The Words And Print The Sentence In Inversed Order
则输出为:
Input a sentence: Vowels in the inputed sentence are: UiIAeooeoeIeeeeAoueoAieeeeIIeeOe
The sentence contains 22 words
And the inversed sentence is: Order Inversed In Sentence The Print And Words The Count And Sentence The In Vowels Collect To Test A Is This Uh
哭了,你写这么长是没人愿意回答的.我也是.你需要什么功能啊,用这么麻烦吗
1、从键盘读入一行最大包含255个字符的句子(句子中没有标点,单词间以一个或多个空格/TAB分隔)。
kbhit()的返回值是什么啊? 有哪个函数可以从键盘读入一个字符(不需要回车直接读入)
java 中怎样实现从键盘读入单个字符?
从键盘上输入一行字符(以ENTER为结束),将其中的大写字母改为小写字母,其他字符不边,然后逆序输出
请问ISO-8859-1包含多少个字符?
编写程序,从键盘读入一个符号,如果它ASII值是偶数则输出1
编写程序,从键盘读入一个符号,如果他的ASCII值是偶数则输出为0。是奇数输出为1呢?
编写程序,从键盘读入一个符号,如果他的ASCII值是偶数则输出为0。是奇数输出为1呢?
用汇编语言编写程序,从键盘读入一个符号,如果他的ASCII值是偶数则输出为0。是奇数输出为1呢?
Windows2000支持长文件名,1个文件名的最大长度可达多少个字符