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 >>
<< Go to Index Page >>
Tags
arithmetic operator
c string
character array
consonent
file
pointer and file
special character
string array
vowel
word count
#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;
}
#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;
}