Thread: plz can u help me with this program

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    14

    Exclamation plz can u help me with this program

    plz can u help me with this program
    this is the question & the answer too...............
    Write a C program that reads several lines of text and then using menu-based interface write the following:



    1- A function count_Alphabet_Words : this function will find how many words in the input text begins with an alphabet

    2- A function count_Vowels : this function will find how many vowel letters are in the input text. (vowels are: a, i, e, u, o)

    3- A function Search_word that will asks for a word and then find how many times this word is reapeated in the input text

    #include<stdio.h>
    #include<string.h>
    #include<ctype.h>
    int countalphawords(char string[100])

    {
    char *p;
    int count=0;
    p=strtok(string," ");
    while (p!=NULL)
    {
    if (isdigit(*p)==0)
    count++;
    p=strtok(NULL," ");
    }
    return (count);
    }

    int countvowels(char string[100])
    {
    char *p,*q;
    int count=0;
    p=strtok(string," ");
    while (p!=NULL)
    {
    q=p;
    while (*q!='\0')
    {
    switch (*q)
    {
    case 'a': count++;
    break;
    case 'e': count++;
    break;
    case 'i': count++;
    break;
    case 'o': count++;
    break;
    case 'u': count++;
    break;
    case 'A': count++;
    break;
    case 'E': count++;
    break;
    case 'I': count++;
    break;
    case 'O': count++;
    break;
    case 'U': count++;
    break;
    }
    q++;
    }
    p=strtok(NULL," ");
    }
    return (count);
    }

    int countsearchword(char string[100],char word[20])
    {
    char *p;
    int count=0;
    p=strtok(string," ");
    while (p!=NULL)
    {
    if (strcmp(p,word)==0)
    count++;
    p=strtok(NULL," ");
    }
    return (count);
    }
    int main ()
    {

    char string[100],key[20],string1[100],string2[100];
    int lines;
    int count=0,count1=0,count2=0;
    int count3=0,count4=0,count5=0;
    printf("Enter # of lines you want to output:\n");
    scanf("%d",&lines);
    printf("Enter the word you want to look for in the text:\n");
    scanf("%s",&key);
    gets(string);
    for(int i=1;i<=lines;i++)
    {
    gets(string);
    strcpy(string1,string);
    strcpy(string2,string);
    count1= countvowels(string);
    count2= countsearchword(string1,key);
    count= countalphawords(string2);
    printf("\nIn line %d there are %d alpha words,%d searchwords,%d vowels\n",i,count,count1,count2);
    count3+=count;
    count5+=count2;
    count4+=count1;
    }
    printf(" \n In the hole text %d alpha words,%d searchwords,%d vowels\n",count3,count4,count5);
    return 0;
    }
    show me the meaning

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    124
    I think that some guys really don't deserve any help.

    itcs,
    how many times have you been told to use code tags?
    Also, when you have any problems with your code, try to break your code into pieces and test them, to find the part of your code that has the problem and post it here.
    Loading.....
    ( Trying to be a good C Programmer )

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    102

    Thumbs up Here is the entire thing man

    Hi man,
    I think this should work:
    [code:]
    #include<stdio.h>
    #include<conio.h>
    #include<string.h>
    #include<ctype.h>
    #include<stdlib.h>
    #define MAXLEN 100
    main()
    {
    char textarr[MAXLEN];
    char *str;
    char* Noofwords(char *);
    char* Noofvowels(char*);
    char* Noofinpchar(char*);
    char *save="";
    puts("Enter the Entire string");
    gets(textarr);
    str=textarr;
    str=Noofwords(textarr);
    str=Noofvowels(str);
    str=Noofinpchar(str);
    }
    char* Noofwords(char *str)
    {
    char *word="";
    char *save="";
    int count=0;
    save=(char *)malloc(strlen(str)+1);
    strcpy(save,str);
    while((word=strtok(str," "))!=NULL)
    {
    if((*word>=65 && *word <=90) || (*word>=96 && *word<=121))
    {
    count++;
    }
    str=str+strlen(word)+1;
    }
    str=save;
    printf("\nNo of Words without Numbers are %d\n",count);
    return str;
    }
    char* Noofvowels(char *str)
    {
    char vowels[10]={'a','e','i','o','u','A','E','I','O','U'};
    int i,count=0;
    char *save="";
    save=(char *)malloc(strlen(str)+1);
    strcpy(save,str);
    while(*str!='\0')
    {
    for(i=0;i<=9;i++)
    {
    if(*str==vowels[i])
    {
    count++;
    break;
    }
    }
    str++;
    }
    printf("\nNo of Vowels are %d\n",count);
    str=save;
    return str;
    }

    char* Noofinpchar(char *str)
    {
    int count=0;
    char ch;
    char *save="";
    save=(char *)malloc(strlen(str)+1);
    strcpy(save,str);
    printf("\nEnter the Character you want\n");
    scanf("%c",&ch);
    while(*str!='\0')
    {
    if(ch==*str)
    {
    count++;
    }
    str++;
    }
    str=save;
    printf("No of characters present are %d\n",count);
    return str;
    }
    [\code]
    Saravanan.
    Saravanan.T.S.
    Beginner.

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    102

    Hi man

    I have pasted just like you. By know you should realize the difficulty of reading without proper tags.
    Saravanan.
    Saravanan.T.S.
    Beginner.

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    itcs: Read about code tags please.

    [edit]I see saravan Getting your own back, eh?!
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >1- A function count_Alphabet_Words
    Code:
    /* For char buff[1001]; */
    while ( fscanf ( in, "%1000s", buff ) == 1 ) {
        if ( isalpha ( buff[0] ) )
            wordCount++;
    }
    >2- A function count_Vowels
    Code:
    int isVowel ( int c )
    {
        c = tolower ( c );
        return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
    }
    
    ...
    
    while ( ( ch = fgetc ( in ) ) != EOF ) {
        if ( isVowel ( ch ) )
            vowels++;
    }
    >3- A function Search_word
    Code:
    while ( fgets ( buff, sizeof buff, in ) != NULL ) {
        if ( strstr ( buff, word ) != NULL )
            matchCount++;
    }
    You're mileage may vary, no refunds, returns, or exchanges.
    My best code is written with the delete key.

  7. #7
    Registered User
    Join Date
    Jul 2003
    Posts
    102

    Lightbulb

    Hi man,
    There is always a fame when something explored and not just download. Can you give full code.
    Thanks,
    Saravanan.
    Saravanan.T.S.
    Beginner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  2. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  3. Plz help wit my program
    By psychaospath in forum C++ Programming
    Replies: 4
    Last Post: 03-10-2006, 05:13 PM
  4. Plz help me to debug my program
    By Bage in forum Linux Programming
    Replies: 1
    Last Post: 04-02-2004, 01:54 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM