plz can u help me with this program
plz can u help me with this program
this is the question & the answer too...............
Write a C program that reads several lines of text and then using menu-based interface write the following:
1- A function count_Alphabet_Words : this function will find how many words in the input text begins with an alphabet
2- A function count_Vowels : this function will find how many vowel letters are in the input text. (vowels are: a, i, e, u, o)
3- A function Search_word that will asks for a word and then find how many times this word is reapeated in the input text
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int countalphawords(char string[100])
{
char *p;
int count=0;
p=strtok(string," ");
while (p!=NULL)
{
if (isdigit(*p)==0)
count++;
p=strtok(NULL," ");
}
return (count);
}
int countvowels(char string[100])
{
char *p,*q;
int count=0;
p=strtok(string," ");
while (p!=NULL)
{
q=p;
while (*q!='\0')
{
switch (*q)
{
case 'a': count++;
break;
case 'e': count++;
break;
case 'i': count++;
break;
case 'o': count++;
break;
case 'u': count++;
break;
case 'A': count++;
break;
case 'E': count++;
break;
case 'I': count++;
break;
case 'O': count++;
break;
case 'U': count++;
break;
}
q++;
}
p=strtok(NULL," ");
}
return (count);
}
int countsearchword(char string[100],char word[20])
{
char *p;
int count=0;
p=strtok(string," ");
while (p!=NULL)
{
if (strcmp(p,word)==0)
count++;
p=strtok(NULL," ");
}
return (count);
}
int main ()
{
char string[100],key[20],string1[100],string2[100];
int lines;
int count=0,count1=0,count2=0;
int count3=0,count4=0,count5=0;
printf("Enter # of lines you want to output:\n");
scanf("%d",&lines);
printf("Enter the word you want to look for in the text:\n");
scanf("%s",&key);
gets(string);
for(int i=1;i<=lines;i++)
{
gets(string);
strcpy(string1,string);
strcpy(string2,string);
count1= countvowels(string);
count2= countsearchword(string1,key);
count= countalphawords(string2);
printf("\nIn line %d there are %d alpha words,%d searchwords,%d vowels\n",i,count,count1,count2);
count3+=count;
count5+=count2;
count4+=count1;
}
printf(" \n In the hole text %d alpha words,%d searchwords,%d vowels\n",count3,count4,count5);
return 0;
}
Here is the entire thing man
Hi man,
I think this should work:
[code:]
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#define MAXLEN 100
main()
{
char textarr[MAXLEN];
char *str;
char* Noofwords(char *);
char* Noofvowels(char*);
char* Noofinpchar(char*);
char *save="";
puts("Enter the Entire string");
gets(textarr);
str=textarr;
str=Noofwords(textarr);
str=Noofvowels(str);
str=Noofinpchar(str);
}
char* Noofwords(char *str)
{
char *word="";
char *save="";
int count=0;
save=(char *)malloc(strlen(str)+1);
strcpy(save,str);
while((word=strtok(str," "))!=NULL)
{
if((*word>=65 && *word <=90) || (*word>=96 && *word<=121))
{
count++;
}
str=str+strlen(word)+1;
}
str=save;
printf("\nNo of Words without Numbers are %d\n",count);
return str;
}
char* Noofvowels(char *str)
{
char vowels[10]={'a','e','i','o','u','A','E','I','O','U'};
int i,count=0;
char *save="";
save=(char *)malloc(strlen(str)+1);
strcpy(save,str);
while(*str!='\0')
{
for(i=0;i<=9;i++)
{
if(*str==vowels[i])
{
count++;
break;
}
}
str++;
}
printf("\nNo of Vowels are %d\n",count);
str=save;
return str;
}
char* Noofinpchar(char *str)
{
int count=0;
char ch;
char *save="";
save=(char *)malloc(strlen(str)+1);
strcpy(save,str);
printf("\nEnter the Character you want\n");
scanf("%c",&ch);
while(*str!='\0')
{
if(ch==*str)
{
count++;
}
str++;
}
str=save;
printf("No of characters present are %d\n",count);
return str;
}
[\code]
Saravanan.