Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old April 14th, 2004, 11:14 PM
Candy Candy is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 1 Candy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
C Programmers Help Me Please

Hi
I have a Home work sheet :'(
It's too hard to me
Help me Please
I tried to do it but still there are errors :-[
ok This is the guistion

Quistion
Write a program that reads a line of text. The program should find the length 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 length. The program should also find and print the average word length.

This is my answer Can you fixe it :Please

---------------------------------------------------------
first try
#include<stdio.h>
#include<string.h>
int main()
{
char text[100];
int lens[50];
int len_all,i,largest,num_words,sum;
float ave;
printf("Enter A Line of Text Please\n");
gets(text);
len_all=strlen(text);
letter="getchar()";
while(strcmp(letter,"\0")!=0)
{
if(strcmp(letter," ")!=0)
lens[i]++;
else
i++;
letter="getchar()";
}

num_words=i++;

for(largest=0,i=0;i<=num_words;i++)
{
if(lens[i]>largest)
largest=i++;
sum+=lens[i];
}

ave=(float)sum/num_words;

printf("The length of The words is %d\n",lens);
printf("The largest length for word number %d\n",largest);
printf("The average of word length= %.2f\n",ave);

return 0;
}
--------------------------------------------------------------

Second Try

#include<stdio.h>
#include<string.h>
int main()
{
char text[100],left[100];
int lens[50];
int len_all,len_left,i,largest,num_words,sum;
float ave;
printf("Enter A Line of Text Please\n");
gets(text);
len_all=strlen(text);

left[100]=strstr(text," ");
len_left=strlen(text);
lens[0]=len_all - len_left;

for(i=1;len_left!=0;i++)
{
len_all=strlen(left);
left[100]=strstr(left," ");
len_left=strlen(left)-1;
lens[i]=len_all - len_left;
}
num_words=i-2;

for(largest=0,i=1;i<=num_words;i++)
{
if(lens[i]>largest)
largest=i++;
sum+=lens[i];
}

ave=(float)sum/num_words;

printf("The length of The words is %d\n",lens);
printf("The largest length for word number %d\n",largest);
printf("The average of word length= %.2f\n",ave);

return 0;
}

-----------------------------------------------------------------------------------------


Please >> Please >> Help Mee :'(
I must Bring it on satrday :-X


Bye

Reply With Quote
  #2  
Old April 16th, 2004, 03:49 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 12
Good Luck

S-

Reply With Quote
  #3  
Old April 16th, 2004, 07:26 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,760 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 5 h 22 m 16 sec
Reputation Power: 443
I haven't done any C or C++ programming since I was in school.
I appears that is why you are doing it too.
If this is a school problem you should really focus on learning how to do it.
If you don't understand how to do simple things like that, then you'll never grasp the harder things you'll be asked to do later.

Reply With Quote
Reply

Viewing: ASP Free ForumsOtherProgramming Help > C Programmers Help Me Please


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway