INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: C Programers Help me Please  (Read 1393 times)

Candy

  • Regular Member
  • Member
  • *
  • Posts: 1
  • Change this by choosing profile
C Programers Help me Please
« on: April 14, 2004, 10:41:24 pm »

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++;
      else
         i++;
      letter="getchar()";
   }

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

   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=len_all - len_left;
   }
   num_words=i-2;

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

   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
Logged

KingSparta

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 20048
Re:C Programers Help me Please
« Reply #1 on: April 15, 2004, 10:55:51 am »

I had A Girl Friend Named Candy Once (30 or so years ago).

Can't Help With The Project however.
Logged
Retired Military, Airborne, Air Assault, And Flight Wings.
Model Trains, Internet, Ham Radio
https://MyAAGrapevines.com
Fayetteville, NC, USA
Pages: [1]   Go Up