请教高手们一道C语言题目,初学者请求帮助!

来源:百度知道 编辑:UC知道 时间:2024/05/14 10:08:11
编写一个C语言程序要求用户输入一段文字,然后按照每个单词的开头字母对这段文字分类统计单词的数量并排序输出。例如,一次运行程序情况如下:
Please input a passage:
The topic of this assignment is about array, pointer and string. In particular, the goal of the assignment is to give you experience for dividing programs into modules and using the pointer for manipulation of string data.

Words begin with t: 7
Words begin with a: 6
Words begin with i: 4
Words begin with p: 4
Words begin with o: 3
Words begin with d: 2
Words begin with f: 2
Words begin with g: 2
Words begin with m: 2
Words begin with s: 2
Words begin with e: 1
Words begin with u: 1
Words begin with y: 1

Total words: 37

#include "stdafx.h"
#include "stdio.h"
#include "string.h"
//在你捻贴的时候不要覆盖程序本身就创建好的#include "stdafx.h" 会出错的 这个是我自己写的 交个朋友就加QQ150535011
struct Type
{
int a;//记录此单词个数
char b;//记录是何字母开始的单词
}phrase[26];//一个结构体数组,分别记录单词种类和个数 也可以通过申明2个数组实现
void main()
{
char str[100];//数组a用来记录各种单词的个数 数组str用来接受字符串
void Record(char str[100]);//返回你总共个数

printf("Please input a passage:\n");
gets(str);
strlwr(str);//此函数作用是将大写字母转换为小写的,也可以自己写,根据题目要求还是换成小写的
Record(str);
}
void Record(char str[])
{
int i,j,k=1,n=1;
struct Type max;//用此做为中介,来进行排序用
for(i=0;str[i]!='\0';i++)
{
if((str[i]<='z')&&(str[i]>='a'))//用来判断是不是第一个字母k==1为第一个字母
{
if(k==1)
{
for(j=1;j<=phrase[0].a&&str[i]!=phrase[j].b;j++);//用结构体第一元素来记录 已经被记录单词的种类个数
//并且来判断是否此类型单词,已经被记录过
if