Techware Labs Header

Forums have moved

See this announcement for more details, or just go directly there.

  #1  
Old 04-14-2004, 10:58 PM
Candy
 
Posts: n/a
Default C Programers 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 04-15-2004, 03:33 PM
StinkyMojo StinkyMojo is offline
Mad Techie
 
Join Date: Dec 2002
Location: Black Mesa Research Facility
Posts: 2,935
Default

I would love to help you but I don't have a compiler on my comp
__________________

Asus A8N SLI - Opteron 148 @ 2.8 under a Zalman 7000cu LED - XFX 7800GT oc'd - 1gb Kingston Hyper X pc3000 BH5 2-2-2 - OCZ ModStream 450watt - WD 36gb Raptor - WD 320gb Storage Drive - Antec Super LanBoy - NEC 3550A 16x DVD Burner
Accessories:
ViewSonic VA1912wb 19" 8ms Widescreen - Plantronics Audio 90 - Logitech Z-640 5.1 - Razer Diamondback Plasma LE on a Ratpadz GS
Linux Box:
Pending..
Reply With Quote
  #3  
Old 04-16-2004, 08:38 PM
vee_ess's Avatar
vee_ess vee_ess is offline
Super Moderator
 
Join Date: Aug 2001
Location: Phoenix, Arizona
Posts: 2,781
Send a message via ICQ to vee_ess Send a message via AIM to vee_ess Send a message via MSN to vee_ess Send a message via Yahoo to vee_ess
Default

What are the errors that you are getting? I don't have a compiler either and don't have the time to install Visual Studio right now. Without knowing what the compilers reports as errors, the only error I see off hand is:

Code:
if(lens[i]>largest) 
largest=i++;
sum+=lens[i];
which should be

Code:
if(lens[i]>largest) 
largest=lens[i];                    //i++ changed to lens[i]
sum+=lens[i];
i++;                                //i++ added because removed previously
Reply With Quote
  #4  
Old 04-16-2004, 10:18 PM
Prometheus Prometheus is offline
Chronique Technique
Lab Master Techie
 
Join Date: Sep 2002
Location: Bellingham,WA
Posts: 3,058
Send a message via AIM to Prometheus
Default

this is why I got a copy of Visual studio .net for 8$
Reply With Quote
  #5  
Old 04-17-2004, 01:27 AM
vee_ess's Avatar
vee_ess vee_ess is offline
Super Moderator
 
Join Date: Aug 2001
Location: Phoenix, Arizona
Posts: 2,781
Send a message via ICQ to vee_ess Send a message via AIM to vee_ess Send a message via MSN to vee_ess Send a message via Yahoo to vee_ess
Default

I have the CD's for a fully functional pre-release, it just takes a while (like an hour!!!!!!!!) to install because of the SDK Framework CD's it requires.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Forum Jump


All times are GMT -5. The time now is 06:40 PM. Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Forum style by ForumMonkeys.