C Program To Count The Number Of Vowels, Consonants, Digits And Special Characters Using File Management Concepts.


In this program input is given by one file and File variable read character one by one from this file.

Input File

Programmer Jd @123

Save this input text file with any name. like input.txt

Code

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){

char str[100];
int i=0;
int vowels=0,consonant=0,digit=0,symbols=0,spaces=0;
FILE *fp;
char ch;
fp = fopen("input.txt", "r");
    if (fp == NULL)
    {

        printf("File not opened ");
        exit(1);
    }
    ch = fgetc(fp);
    printf("Your string is :\n");
    while (!feof(fp))
    {
        str[i++]=ch;
        ch = fgetc(fp);
    }
    str[i]='\0';
    printf("%s",str);
    fclose(fp);


for(i=0;str[i]!='\0';i++)
{
if(str[i]=='a' || str[i]=='A' || str[i]=='e' || str[i]=='E' || str[i]=='i' || str[i]=='I' || str[i]=='o' || str[i]=='O' || str[i]=='u' || str[i]=='U'){
vowels++;
}
else if((str[i]>='a' && str[i]<='z')||(str[i]>='A' && str[i]<='Z'))
{
consonant++;
}
else if(str[i]>='0' && str[i]<='9'){
digit++;
}
else if (str[i]==' ')
{
spaces++;
}
else{
symbols++;
}
}
printf("\nVowels : %d",vowels);
printf("\nConsonant : %d",consonant);
printf("\nDigit : %d",digit);
printf("\nSpecialSymbols : %d",symbols);
printf("\nWhite spaces: %d", spaces);

return 0;
}

Output






 

Comments

Popular posts from this blog

Write A Program To Print Hello World Using Lex

Create a Student registration form using following tags form,input,textarea,button,select,optio. The registration form must consist of following information: first name,Middle name,last name, gender(use radio button),address,phone no,email id,hobbies(use checkbox),city,state,country,collage name (use dropdown menu).