关于C语言的~~~急救~~~就一天时间~~~~

来源:百度知道 编辑:UC知道 时间:2024/06/17 05:49:11
教C语言的老师是苏格兰的~~实在听不懂
这是老师布置的作业~~星期一就让交~~~火烧眉毛中~~~~
Write a prgram that read a string and calculates how many many rds,letter,and lines there are .The program is in 3 parts:
Part1:Basic Program
1.Program finds out how many words are in the string
2. Finds out the following:
1.How many words are in the string
2.How many letters are in the string
3.The word with the most letters
4.The word with the lowest number of letters
5.The average number of letters per word
3.displays a report about everything above

Part2:Change the above program:
1.The program reads a string from a file instead
2.The report is written to a file
3.Count how many lines are in the program
4.Calculate the average number of words per line there are
5. Calculate the average number of letters per line there are

Part3:Change the above program:
1.Build a calculator program:
1.The

#include<stdio.h>
#include<string.h>

int countLetters(char*str){
int length=strlen(str);
int letter_count=0;
for(int i=0;i<length;i++){
if(str[i]>='a'&&str[i]<='z'||str[i]>='A'&&str[i]<='Z')letter_count++;
}
return letter_count;
}

int countWords(char*str){
int length=strlen(str);
int index=0;
int wordsCount=0;
while(index<length){
for(;index<length;index++)if(str[index]!=' ')break;
if(index==length)break;
wordsCount++;
for(;str[index]!=' '&&index<length;index++);
}
return wordsCount;
}

//mostOrLowest==0 refers to finding the letter having most letters
//mostOrLowest==1 refers to finding the letter having lowest letters
char*wordWithMostOrLowestLetters(char*str,int mostOrLowest){
int length=strlen(str);
int index=0;
int wordsCo