You must Sign In to post a response.
  • Category: Programming

    Program to count number of characters and print the vowels in the text.


    Preparing for C programming exams? Looking out for solution to programming problems on this page? No worries, plan your preparation with solutions and advice from our ISC experts.

    Following is a question that was asked in the MSBTE (Maharashtra State Board of Technical Education, Mumbai) Diploma in Electronics Engineering sample question paper of C Programming Language(22218).

    This question is asked for 06 marks and hence requires some explanation along with the program code. Please let me know the solution.

    Q) Write a C Program to count the number of characters and print the vowels present in the entered text.[6 Marks]
  • Answers

    1 Answers found.
  • String is nothing but the character array. In C programming if user want to accept the text with white spaces then user have use special format specifier instead of %s, which is known %[^character]. In this format specifier we can use any alphabet or back slash character constant at the place of character.
    e.g. scanf("%s",text); here when we use first white space (tab key, enter key, space bar) the string terminates.
    scanf("%[^\n]",text); here string accept the data till enter key(\n) is not encountered. So using this format specifier user can accept the text with white spaces. Here we use '\n' at the place of character.

    Below is the program which counts total number of alphabets and total number of vowels in the given text.
    Please include stdio.h and conio.h header files before main function.

    //PROGRAM TO FIND TOTAL ALPHABETS AND TOTAL VOWELS IN GIVEN TEXT.
    #include
    #include
    void main(void)
    {
    char text[100];
    int i=0,c=0,v=0;
    clrscr();
    printf("Enter any text here\n");
    scanf("%[^\n]",text);
    clrscr();
    printf("\n Given text is %s",text);
    while(text[i]!='\0')
    {
    if((text[i]>=65 && text[i]<=90)||(text[i]>=97 && text[i]<=122))
    {
    c++;
    }
    if((text[i]=='a'||text[i]=='e'||text[i]=='i'||text[i]=='o'||text[i]=='u'||text[i]=='A'||text[i]=='E'||text[i]=='O'||text[i]=='I'||text[i]=='U'))
    {
    v++;
    }
    i++;
    }
    printf("\nTotal alphabets are %d ",c);
    printf("\nTotal vowels are %d ",v);
    getch();
    }

    In the above program in while loop condition '\0' is used. This '\0' is nothing but null character which is end of the string.


  • Sign In to post your comments