Friday, 20 March 2015

Character and Word Count using Pointer


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# include<stdio.h>

int main()
{
    char array[100],c;
    int i, word=0,count=0;
    char *p;

    for(i=0;;i++)
    {
        p=&array[i];
        scanf("%c",&c);
        
        if(c=='\n')
        {
            *p='\0';
            break;
        }
        *p=c;
  count++;
    }

    for(p=&array[0];*p;p++)
    {
        if(((*p<='z' && *p>='a') || (*p<='Z' && *p>='A')) && !((*(p+1)<='z' && *(p+1)>='a') ||(*(p+1)<='Z' && *(p+1)>='A')))
        {
            word++;              
        }
    }

       
    printf("Total Word: %d\n",word);      
    printf("Total Character: %d\n",count);

    return 0;
}

0 comments:

Post a Comment

 

Subscribe to our Newsletter

Contact our Support

Through the contact form

Our Team Memebers