Index-1              Index-2              Home Page

c program to count vowel, consonant, arithmetic operator, special character, word and sentence

Write a c program to count vowel, consonant, arithmetic operator, special character, word and sentence from a string in a file and save the output in another file


<< Go to Index Page >>

7 comments:

  1. #include
    #include
    int main()
    {
    FILE *source,*target;
    char source_file[20],target_file[20],ch[250];
    int i,v=0,c=0,a=0,w=1,s=0;
    printf("Enter the file name to retrive string:");
    gets(source_file);
    source=fopen(source_file,"r");
    fgets(ch, 255, (FILE*)source);
    printf("3: %s\n", ch );
    for(i=0;ch[i]!='\0';++i)
    {
    if(ch[i]=='a' || ch[i]=='e' || ch[i]=='i' || ch[i]=='o' || ch[i]=='u' ||
    ch[i]=='A' || ch[i]=='E' || ch[i]=='I' || ch[i]=='O' || ch[i]=='U')
    ++v;

    else if((ch[i]>='a' && ch[i]<='z')|| (ch[i]>='A' && ch[i]<='Z'))
    ++c;

    else if(ch[i]=='+' || ch[i]=='-' || ch[i]=='*' || ch[i]=='/' || ch[i]=='%')
    ++a;

    else if(ch[i]==' ')
    ++w;

    else if(ch[i]=='.')
    ++s;

    }
    printf("Vowel: %d\n",v);
    printf("Consonent: %d\n",c);
    printf("Arithmetic Operator: %d\n",a);
    printf("Word: %d\n",w);
    printf("Sentence: %d\n",s);

    printf("Enter a File name to Copy Answer:");
    gets(target_file);
    target=fopen(target_file,"w");
    fprintf(target,"Vowel: %d\n Consonent: %d\nOperator: %d\nWord: %d\nSentence: %d",v,c,a,w,s);
    fclose(target);
    fclose(source);
    return 0;
    }

    ReplyDelete
  2. #include
    #include

    int main()
    {
    char a, b=' ', l=0, v=0, c=0, n=0, sp=0, bs=0, w=0, li=0, ao=0;

    do
    {
    a=getchar ();
    if (a=='\n')
    break;

    if (isspace(a)&&a!='\n')
    {
    if (isalpha(b)||(ispunct(b)&&b!='.'&&b!='!'&&b!='?'))
    w++;
    bs++;
    }
    else if (isalpha (a))
    {
    l++;
    a=tolower(a);
    if (a=='a'||a=='e'||a=='i'||a=='o'||a=='u')
    v++;
    else
    c++;
    }
    else if (isdigit(a))
    n++;
    else if (ispunct(a))
    {
    sp++;
    if (a=='+'||a=='-'||a=='/'||a=='*'||a=='%')
    ao++;
    if (a=='.'||a=='!'||a=='?')
    {
    li++;
    if (isalpha(b))
    w++;
    }
    }
    b=a;
    } while (a!='\n');

    if (isalpha(b))
    w++;

    printf("letter= %d (vowel= %d, consonant= %d)\nWord= %d\ndigit= %d\nSpecial char= %d (arithmatic operator= %d)\nBlank Space= %d\nSentence= %d", l, v, c, w, n, sp, ao, bs, li);

    return 0;
    }

    ReplyDelete
  3. ////CSE 56 Batch..Uttara..
    ////ID 201730750
    ///Write a c program to count vowel, consonant, arithmetic operator, special character, word and sentence from a string.////


    #include

    int main()
    {
    char sentence[100];
    int i, vowels = 0, consonants = 0,count=0,Scount=0,c=0,
    alphabets =0, digits =0, special = 0,spaces=0;

    printf("Enter a sentence \n");
    gets(sentence);
    for (i = 0; sentence[i] != '\0'; i++)
    {

    if ((sentence[i] == 'a' || sentence[i] == 'e' || sentence[i] ==
    'i' || sentence[i] == 'o' || sentence[i] == 'u') ||
    (sentence[i] == 'A' || sentence[i] == 'E' || sentence[i] ==
    'I' || sentence[i] == 'O' || sentence[i] == 'U'))
    {
    vowels = vowels + 1;
    }
    else
    {
    consonants = consonants + 1;
    }


    if(sentence[c] == '.' || sentence[c] == '?' || sentence[c] == '!')
    Scount++;
    c++;

    if (sentence[i] == ' ')
    {
    count++;
    }

    if((sentence[i] >= 'a' && sentence[i] <= 'z') || (sentence[i] >= 'A' && sentence[i] <= 'Z'))
    {
    alphabets++;
    }
    else if(sentence[i] >= '0' && sentence[i] <= '9')
    {
    digits++;
    }
    else if(sentence[i] == ' ')
    {
    spaces++;
    }
    else
    special++;




    }
    printf("Number of vowels in %s = %d\n", sentence, vowels);

    printf("Number. of consonants in %s = %d\n", sentence, consonants);

    printf("number of words in given word are: %d\n", count + 1);

    printf("number of sentence in given sentence are: %d\n", Scount + 1);

    printf("number of special Character in given sentence are: %d\n", special);



    }

    ReplyDelete
  4. Name : Md. Zoynul Abedin
    Roll : 201820591
    Batch : 58-th


    ** c++ program to count vowel, consonant, arithmetic operator, special character, word and sentence :

    #include
    #include
    using namespace std;

    int main()
    {
    char line[150];
    int vowels, consonants, digits, spaces;

    vowels = consonants = digits = spaces = 0;

    cout << "Enter a line of string: ";
    cin.getline(line, 150);
    for(int i = 0; line[i]!='\0'; ++i)
    {
    if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||
    line[i]=='o' || line[i]=='u' || line[i]=='A' ||
    line[i]=='E' || line[i]=='I' || line[i]=='O' ||
    line[i]=='U')
    {
    ++vowels;
    }
    else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
    {
    ++consonants;
    }
    else if(line[i]>='0' && line[i]<='9')
    {
    ++digits;
    }
    else if (line[i]==' ')
    {
    ++spaces;
    }
    }

    cout << "Vowels: " << vowels << endl;
    cout << "Consonants: " << consonants << endl;
    cout << "Digits: " << digits << endl;
    cout << "White spaces: " << spaces << endl;

    getch();
    }

    Output :
    Enter a line of string: Which of the following is closest to 27.8 × 9.6?
    Vowels: 10
    Consonants: 21
    Digits: 5
    White spaces: 9

    ReplyDelete
  5. ** c++ program to count vowel, consonant, arithmetic operator, special character, word and sentence :
    #include
    #include
    using namespace std;
    int main()
    {
    char line[150];
    int vowels, consonants, digits, spaces;

    vowels = consonants = digits = spaces = 0;

    cout << "Enter a line of string: ";
    cin.getline(line, 150);
    for(int i = 0; line[i]!='\0'; ++i)
    {
    if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||
    line[i]=='o' || line[i]=='u' || line[i]=='A' ||
    line[i]=='E' || line[i]=='I' || line[i]=='O' ||
    line[i]=='U')
    {
    ++vowels;
    }
    else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
    {
    ++consonants;
    }
    else if(line[i]>='0' && line[i]<='9')
    {
    ++digits;
    }
    else if (line[i]==' ')
    {
    ++spaces;
    }
    }

    cout << "Vowels: " << vowels << endl;
    cout << "Consonants: " << consonants << endl;
    cout << "Digits: " << digits << endl;
    cout << "White spaces: " << spaces << endl;

    getch();
    }

    ReplyDelete
  6. /////////////////////
    // Khorshed Alam //
    // ID: 201730438 //
    // 56 batch, CSE //
    /////////////////////

    #include <iostream>
    #include <fstream>
    #include <algorithm>

    using namespace std;

    class homeWork{
    public:
    counter(){
    int vowel, consonant, alphabet, arithmetic, numeric, special, word, sentence;
    vowel = consonant = alphabet = arithmetic = numeric = special = word = sentence = 0;

    char ch[] = "Hello this is nothing. for you 10+2+3=6 and nothing *#.";

    for(int i=1; ch[i] != '\0'; i++){
    if ((ch[i] >= 'A' && ch[i] <= 'Z') || (ch[i] >= 'a' && ch[i] <= 'z')){
    if(ch[i]=='A' || ch[i]=='a' || ch[i]=='E' || ch[i]=='e' || ch[i]=='I' || ch[i]=='i' || ch[i]=='O' || ch[i]=='o' || ch[i]=='U' || ch[i]=='u'){
    vowel++;
    } else {
    consonant++;
    }
    alphabet++;
    } else if (ch[i]=='0' || ch[i]=='1' || ch[i]=='2' || ch[i]=='3' || ch[i]=='4' || ch[i]=='5' || ch[i]=='6' || ch[i]=='7' || ch[i]=='8' || ch[i]=='9'){
    numeric++;
    } else if (ch[i] == ' '){
    word++;
    } else if (ch[i] == '.'){
    sentence++;
    } else{
    if(ch[i]=='+' || ch[i]=='-' || ch[i]=='*' || ch[i]=='/' || ch[i]=='%'){
    arithmetic++;
    } else {
    special++;
    }
    }
    }

    cout<<"Total number of vowel is :"<<vowel<<endl;
    cout<<"Total number of consonant is :"<<consonant<<endl;
    cout<<"Total number of alphabet is :"<<alphabet<<endl;
    cout<<"Total number of arithmetic is :"<<arithmetic<<endl;
    cout<<"Total number of numeric is :"<<numeric<<endl;
    cout<<"Total number of special character is :"<<special<<endl;
    cout<<"Total number of word is :"<<word+1<<endl;
    cout<<"Total number of sentence is :"<<sentence<<endl;
    }
    };
    main() {
    homeWork hw;
    hw.counter();
    }

    ReplyDelete
  7. Id: 201710251
    Link: https://drive.google.com/open?id=1hVFxR-wNPdJXkMmJZ0kXOf4QhLUmbK4f

    ReplyDelete