c program to count word and sentence

Write a c program to count word and sentence from a given string as like "I love Bangladesh."


<< Go to Index Page >>

1 comment:

  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