Link to home
Start Free TrialLog in
Avatar of saad302
saad302

asked on

I need "a beginer level" c code to solve the following question? - urgent

Please help me to write "a beginer level" c code to solve the following question?

"Write a program that reads a line of text. The program should find the lenght of each word in the string and stores it in an array. The program should print the resulting array, and the index of the word that has the largest lenght, the program should also find and print the average word lenght?"

Please treat this question "urgent". by this Saturday (16 GMT) i need the answer?

Your help is highly appreciated.

Regards

Avatar of mokule
mokule
Flag of Poland image


Have you written anything so far?
ASKER CERTIFIED SOLUTION
Avatar of brettmjohnson
brettmjohnson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of saad302
saad302

ASKER

Thank you brettmjohnson for your tips. it's not a homework as it's a tetorial to give me an idea how to deal with string, other questions i will have to do it my self (preparation for forther questions)?

Mokule, if you still can give help today, it will be appreciated...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Avik Dasgupta
Avik Dasgupta
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of saad302

ASKER

Thank you Guys for your help...

Avik, Ankuratvb your tips were very helpfull.

Regards
Hi,

>I think tackling the problem will be easier if u create an array of structure, like:
>struct word{
>char str[20]; // this will exceed normal size of words
>int count;
>int index;
>};
>struct word w[70]; // say max number of words

Do you need to store the words seperately in char arrays as well.
coz it doesnt say so in your original problem defn.
It says you just want the length of each word stored in an array.

In that case,the struct thing would waste memory.
>>In that case,the struct thing would waste memory.

Well, I agree. But certainly it is a good approach to make the problem more general and flexible. The structure says everything. It keeps track of the words, their lengths and also their indexes. The problem I have tackled would lead to  only a single scan of the string storing all necessary information about the string in the proper fields of the structure.
It's all in a nutshell :)

Avik.