0

Please can you tell me where I've gone wrong !!!

thanks Sam

#include<stdio.h>

#include<stdlib.h>

#include<ctype.h>

#include<string.h>



int main()

{

    char array[80]; // input array

    int i=0; // loop counter 1

    int vo=0; // vowels

    int co=0; // consonents

    int ot=0; // other characters

    

    

    printf("please enter string\n");

    fflush(stdin);

    gets(array);

    

    while(i!=80)

    {

        if(isalpha(array[i]))

        {

            if(array[i]==(('a')||('A')||('e')))

            {

                vo++;

            }

            

            else 

            {

               co++;

            }

        }

            

        else 

        {

           ot++;

        }

        

    }

    

    printf("%d vowels, %d characters\n",vo,co);

    system("pause");

}
3
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by vinitmittal2008
0

Please get out of the habit of using gets(), its a very dangerous function. A much better solution is fgets().

Also...

Your while statement assumes that the fetched c-string is 80 characters long?

while(i!=80)

shouldn't it be

while(i <= strlen(array))

Also this next line is incorrect

if(array[i]==(('a')||('A')||('e')))

It should be

if ( array[i] == (('a') || array[i] == ('A') || array[i] == ('e')))

Plus we have move vowels than 'a' and 'e'

Edited by gerard4143: n/a

0

Here you went Wrong !!

Are you sure that you will input 80 char long string every time...

while(i!=80)

It should be like

while(array[i]!='\0') // A string in c comes to end when it reaches '\0'

Also you are running a never ending while loop because there is no incrementation of i inside while loop..

i++;

Also this line is wrong

if(array[i]==(('a')||('A')||('e')))

Check for all vovels a,e,i,o,u and make it like

if ( array[i] == ('a') || array[i] == ('A') || array[i] == ('e') || array[i] == ('E'))

Also add condition for 'i' ,'o' ,'u' in the above if statement..

And print

printf("%d vowels, %d characters, %d others\n",vo,co,ot);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.