-->
Showing posts with label program to count total number of words. Show all posts
Showing posts with label program to count total number of words. Show all posts

program to count total number of words,space,consonants in a string using pointer

using codeblocks
-----------------------------------------------------------------------

//program to reverse a string using pointer//comment of program
#include <stdio.h>                         //header file
#include<ctype.h>
int main()                              //main function
{
    char name[40];                     //character declaration
    char *p;                          //pointer declaration.
    int length,vowel=0,conso=0,space=0,words=1;
    puts("enter string\n");           //display of message
    gets(name);                      // gets data/string
    length=strlen(name);             //stores length of string
    p=name+length;        // assigning total address as in given string; it becomes total taken from variable length starting from 0.
                      //p=name takes address location 0 to pointer.
    while(p>=name)                 //the value of 'p' decreases from location 15 until it reaches 0.
    {
        if(*p==' ')                 //prints the value stored in particular location
        {
            space++;
        }

        else if(tolower(*p)=='a' ||tolower(*p)=='e' || tolower(*p)=='i' || tolower(*p)=='o' || tolower(*p)=='u')
        {
            vowel++;
        }
        else if(tolower(*p)!='a' ||tolower(*p)!='e' || tolower(*p)!='i' ||
                tolower(*p)!='o' || tolower(*p)!='u' ||
                *p!=' ' || *p!='.')
        {
            conso++;
        }
        p--;
    }
    printf("total vowel=%d,total consonants=%d,total spaces=%d,total words=%d",vowel,conso,space,space+1);
    return 0;
}

----------------------------------------------------------------------------------------------------------
using turbo c++
----------------------------------------------------------------------------------------------------
//program to reverse a string using pointer//comment of program
#include <stdio.h>                         //header file
#include<ctype.h>
#include<conio.h>
int main()                              //main function
{
    char name[40];                     //character declaration
    char *p;                          //pointer declaration.
    int length,vowel=0,conso=0,space=0,words=1;
    puts("enter string\n");           //display of message
    gets(name);                      // gets data/string
    length=strlen(name);             //stores length of string
    p=name+length;        // assigning total address as in given string; it becomes total taken from variable length starting from 0.
                      //p=name takes address location 0 to pointer.
    while(p>=name)                 //the value of 'p' decreases from location 15 until it reaches 0.
    {
        if(*p==' ')                 //prints the value stored in particular location
        {
            space++;
        }

        else if(tolower(*p)=='a' ||tolower(*p)=='e' || tolower(*p)=='i' || tolower(*p)=='o' || tolower(*p)=='u')
        {
            vowel++;
        }
        else if(tolower(*p)!='a' ||tolower(*p)!='e' || tolower(*p)!='i' ||
                tolower(*p)!='o' || tolower(*p)!='u' ||
                *p!=' ' || *p!='.')
        {
            conso++;
        }
        p--;
    }
    printf("total vowel=%d,total consonants=%d,total spaces=%d,total words=%d",vowel,conso,space,space+1);
getch();    
return 0;
}