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");

}

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'

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);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.