help me to my case study..

help me to my case study.. pls...

using array, strings,loop..

input:

Enter a statement: the quick brown fox

output:

word1: the................vowel: 1
word2: quick...............vowel: 2
word3: brown.............vowel: 1
word4: fox.................vowel: 1

program should analyze how many vowels in every words you enter and show the words as shown above(the periods is not included to the program)...

thanks... ill appreciated if you would help me..
[525 byte] By [neo012] at [2007-11-20 1:00:53]
# 1 Re: help me to my case study..
Its a simple homework. First show us your effort and many will help you. Basically what you need is how to handle array of characters.
kumaresh_ana at 2007-11-9 1:07:12 >
# 2 Re: help me to my case study..
ahh.. ok ill try.. ill show my code later.. thanks..
neo012 at 2007-11-9 1:08:10 >
# 3 Re: help me to my case study..
about my last post.. can anyone show me a example of how to handle arrays of characters?.. i want to try my case study but i have no idea.. thanks..
neo012 at 2007-11-9 1:09:14 >
# 4 Re: help me to my case study..
[ merged threads ]
cilu at 2007-11-9 1:10:08 >
# 5 Re: help me to my case study..
Please read to this FAQ ( http://www.dev-archive.com/forum/showthread.php?t=366302) first.
cilu at 2007-11-9 1:11:15 >
# 6 Re: help me to my case study..
Read up on the following:

1. std::string class (http://msdn2.microsoft.com/en-us/library/5zz6weyz.aspx) - available under <string> header
2. std::count_if (http://msdn2.microsoft.com/en-us/library/w2d7w2x2.aspx) - available under <algorithm> header

These two should help you achieve your task. Read the illustrations well. Try coding the solution. Show what you have done until the point from where you are not able to code further. I will help you. But you have put some effort.

//Even just the first one should be enough - shouldn't need second (if for loops are used). I am assuming you know how to get inputs from standard streams.
exterminator at 2007-11-9 1:12:14 >
# 7 Re: help me to my case study..
help me to my case study.. pls...

using array, strings,loop..

input:

Enter a statement: the quick brown fox

output:

word1: the................vowel: 1
word2: quick...............vowel: 2
word3: brown.............vowel: 1
word4: fox.................vowel: 1

program should analyze how many vowels in every words you enter and show the words as shown above(the periods is not included to the program)...

thanks... ill appreciated if you would help me..

Plz do not cross post your question in multiple threads.
Ejaz at 2007-11-9 1:13:13 >
# 8 Re: help me to my case study..
i try my best in this program but it seems that i need some tutor.. will you figure it out the error... please...

im using turbo c...

#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char x[100],y[50][50];
int i=0, j=0, ctr=0, ctr2=0, tmp[50], k, cv=0;
clrscr();
printf("Enter statement: ");
gets(x);
while (i<strlen(x))
{
if (x[i] !=' ')
{
for (k=0;k<strlen(x);k++)
{
if (x[k]=='a' || x[k]=='A' || x[k]=='e' || x[k]=='E' || x[k]=='i' || x[k]=='I' || x[k]=='o' || x[k]=='O' || x[k]=='u' || x[k]=='U')
{
cv++;
}
}
printf(" vowels: %d", cv);
}
{
y[ctr][ctr2++]=x[i];
}
else
{
tmp[ctr]=ctr2;
ctr++;
ctr2=0;
}
i++;
}
tmp[ctr]=ctr2;
ctr++;
for (i=0;i<ctr;i++)
{
for (j=0;j<tmp[i];j++)
{
printf("%c", y[i][j]);
}
printf("\n");
}
getch();
return 0;
}

the program should output is...

enter statment: the quick brown fox

word1= the...................vowels: 1
word2= quick.................vowels: 2
word3= brown...............vowels: 1
word4= fox...................vowels: 1

the periods is not included.
neo012 at 2007-11-9 1:14:21 >
# 9 Re: help me to my case study..
will you figure it out the error... please...What error?

- petter
wildfrog at 2007-11-9 1:15:16 >
# 10 Re: help me to my case study..
I think you are getting a compile error.

char x[100],y[50][50]; //why need y[50][50]?
int i=0, j=0, ctr=0, ctr2=0, tmp[50], k, cv=0;
clrscr();
printf("Enter statement: ");
gets(x);
while (i<strlen(x))
{
if (x[i] !=' ')
{
for (k=0;k<strlen(x);k++)
{
if (x[k]=='a' || x[k]=='A' || x[k]=='e' || x[k]=='E' || x[k]=='i' || x[k]=='I' || x[k]=='o' || x[k]=='O' || x[k]=='u' || x[k]=='U')
{
cv++;
}
}
printf(" vowels: %d", cv);
} //now cv will hold the number of vowels in the whole input not each word

//where is the if statement?
{
y[ctr][ctr2++]=x[i];
}
else//i have no clue of what you are trying to do here
{
tmp[ctr]=ctr2;
ctr++;
ctr2=0;
}
i++;
}
//i have no clue of what you are trying to do here
tmp[ctr]=ctr2;
ctr++;
for (i=0;i<ctr;i++)
{
for (j=0;j<tmp[i];j++)
{
printf("%c", y[i][j]);
}
printf("\n");
}
getch();
return 0;
}

The check for space has to be moved inside the loop

gets(x);
i = 0, wordcount = 1;
while(x[i])//till we counter null character loop
{
count = 0;
while(x[i] == ' ') //removes reduntant spaces
{
++i;
}

printf("word%d : ", wordcount);
for(; x[i] != ' ' && x[i] != '\0'; ++i)//break if current character is null or space
{
printf("%c", x[i]);
//check here for if x[i] is vowel and increment count
}
printf("....vowels : %d\n", count);

//prepare for next word
if(x[i])
{
++i;
++wordcount;
}
}
kumaresh_ana at 2007-11-9 1:16:22 >
# 11 Re: help me to my case study..
I will give you pseudo code for this.. and then try re-implementing your program.1. Take the input line from command line
2. Count the number of spaces (store in ineteger variable space_count)
3. Use strtok to get the various words out of that sentence and store them in another array (this array's size will be space_count + 1)
4. Create another integer array of the same size as the number of words. We will use this to keep vowel count of each word (size = space_count+1)
5. Now, use a for-loop to loop through the above created array. (let loop index be 'i')
//Inside for-loop
//Examine each word for the things that you want to find
a. Use another for-loop to check each character of a word. (let loop index be 'j')
How long will this for-loop run? Use strlen function to get the count of characters in the word
b. Check if the character is among - 'a', 'e', 'i', 'o', 'u'
//It would be better if you compared those character after changing them to lower case
//You can change to lower case using tolower() function
//Otherwise, you will need to compare them with 'A'/'E'/'I'/'O'/'U' also.

//Inside the if statement do the following:
i. Update the vowel counter for that word
ii. How do you get that vowel counter ? It will be the i-th element of the integer array we created in 3.

//End for
//End for
6. Print the result in the format expected using the words array and integer array
7. return happily from mainTry making the program and be specific about whichever stage of the algorithm above is not clear or you are having problem with.. I will help you.
exterminator at 2007-11-9 1:17:18 >
# 12 Re: help me to my case study..
looks like cilu needs to merge even more threads
NMTop40 at 2007-11-9 1:18:22 >
# 13 Re: help me to my case study..
[ Merged threads ]

neo012,

Please do not create multiple threads for the same problem. Thank you very much.
Andreas Masur at 2007-11-9 1:19:18 >
# 14 Re: help me to my case study..
I will give you pseudo code for this.. and then try re-implementing your program.
I think that neo012 is a beginner. So, it will be better if he knows the know how of variuos logic. Instead of using the library routines one could learn a lot by doin it all by himself.
kumaresh_ana at 2007-11-9 1:20:18 >
# 15 Re: help me to my case study..
hey guys, i think i know a bit.. but im only confusing with this code:

for ( k=0; k<strlen(x); k++)
{
if (x[k]=='a' || x[k]=='A' || x[k]=='e' || x[k]=='E' || x[k]=='i' || x[k]=='I' || x[k]=='o' || x[k]=='O' || x[k]=='u' || x[k]=='U')
{
cv++;
}
}
printf("vowels: %d", cv);

i dont know where i can insert that to analyze if the word i enter have a vowel and count it..

here is my program and please teach me where can i insert that.. please...

#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char x[100],y[100][100];
int i=0, j=0, ctr=0, ctr2=0, tmp[100], k, cv=0;
clrscr();
printf("Enter statement: ");
gets(x);
while (i<strlen(x))
{
if (x[i] !=' ')
{
y[ctr][ctr2++]=x[i];
}
else
{
tmp[ctr]=ctr2;
ctr++;
ctr2=0;
}
i++;
}
tmp[ctr]=ctr2;
ctr++;
for (i=0;i<ctr;i++)
{
for (j=0;j<tmp[i];j++)
{
printf("%c", y[i][j]);
}
printf("\n");
}
getch();
return 0;
}

im just using turbo c.. coz im noob programmer.. T_T
neo012 at 2007-11-9 1:21:22 >
# 16 Re: help me to my case study..
The second piece is fine in extracting each word out of a space seperated sentence and display it. Similarly, to find number of vowels in each of these words the first piece of code wont help. A little modification is needed. Here you go.

int vowelsCount[100]; //keeps track of number of vowels in each word

for(i = 0; i < 100; ++i) vowelsCount[i] = 0;
while (i<strlen(x))
{
if (x[i] !=' ')
{
y[ctr][ctr2++]=x[i];
// if (x[i]=='a' || x[k]=='A' ....) check for vowel
{
++vowelsCount[ctr];
}
}
else
{
tmp[ctr]=ctr2;
ctr++;
ctr2=0;
}
i++;
}
tmp[ctr]=ctr2;
ctr++;
for (i=0;i<ctr;i++)
{
for (j=0;j<tmp[i];j++)
{
printf("%c", y[i][j]);
}
printf("...Vowels : %d\n", vowelsCount[ctr]);
}

But note that this peice of code looks so messy.
kumaresh_ana at 2007-11-9 1:22:21 >
# 17 Re: help me to my case study..
wow cool.. i understand know.. thanks kumaresh ana..

i know its so messy.. ^_^ thats the way my prof teach us..
neo012 at 2007-11-9 1:23:26 >
# 18 Re: help me to my case study..
C has a function strchr. Why not use it. Use "aeiouAEIOU" perhaps as your vowel string.

strchr returns a pointer to the vowel but you want 1/0 so use:

int vowel_count( char ch )
{
return strchr( "aeiouAEIOU", ch ) ? 1 : 0;
}


We'll cut out locale issues and accented vowels for this purpose. But you could make vowel_count use pseudo-locales by not hard-coding in the vowel-string to the function.
NMTop40 at 2007-11-9 1:24:22 >
# 19 Re: help me to my case study..
the code of kumaresh ana is not working well.. it says the vowel of each words are 0(zero)..

@nmtop40

i cant use that because my prof will know that im cheating.. coz he dont teach us by using strchr commands.. only basics can i only explain..
neo012 at 2007-11-9 1:25:25 >
# 20 Re: help me to my case study..
How is using a standard library function "cheating"?

It's trivial to write your own strchr. We'll make it return const char * thus:

const char * own_strchr( const char * input_string, char search_char )
{
if ( input_string == NULL )
{
return input_string;
}
for ( ; *input_string; ++input_string )
{
if ( *input_string == search_char )
{
return input_string;
}
}
return NULL;
}
NMTop40 at 2007-11-9 1:26:27 >
# 21 Re: help me to my case study..
Ok, here is the right code. I have tested it.

#include<stdio.h>
#include<conio.h>
#include<string.h>

int main(int argc , char** argv)
{
char x[100],y[100][100];
int i=0, j=0, ctr=0, ctr2=0, tmp[100], k, cv=0;
int vowelsCount[100]; //keeps track of number of vowels in each word

printf("Enter statement: ");
gets(x);

for(i = 0; i < 100; ++i) vowelsCount[i] = 0;
i = 0;
while (i<strlen(x))
{
if (x[i] !=' ')
{
y[ctr][ctr2++]=x[i];
if (x[i]=='a' || x[i]=='A' || x[i]=='E' || x[i]=='e' || x[i]=='I' || x[i]=='i' || x[i]=='O' || x[i]=='o' || x[i]=='U' || x[i]=='u')
{
++vowelsCount[ctr];
}
}
else
{
tmp[ctr]=ctr2;
ctr++;
ctr2=0;
}
i++;
}
tmp[ctr]=ctr2;
ctr++;
for (i=0;i<ctr;i++)
{
for (j=0;j<tmp[i];j++)
{
printf("%c", y[i][j]);
}
printf("...Vowels : %d\n", vowelsCount[i]);
}
}

I guess you would have figured that out.
kumaresh_ana at 2007-11-9 1:27:26 >
# 22 Re: help me to my case study..
How is using a standard library function "cheating"?

It's trivial to write your own strchr. We'll make it return const char * thus:

Why do we need this as we already have a routine?
kumaresh_ana at 2007-11-9 1:28:27 >
# 23 Re: help me to my case study..
We don't but his professor does.
NMTop40 at 2007-11-9 1:29:36 >
# 24 Re: help me to my case study..
We don't but his professor does.
Good one! You are humorus....
kumaresh_ana at 2007-11-9 1:30:37 >
# 25 Re: help me to my case study..
yes.. thanks kumaresh ana...
neo012 at 2007-11-9 1:31:31 >
# 26 Re: help me to my case study..
ei kumaresh ana.. what is the use of vowelcount[i]=0; i=0 under of for(i=0; i<100; i++)?

#include<stdio.h>
#include<conio.h>
#include<string.h>

int main(int argc , char** argv)
{
char x[100],y[100][100];
int i=0, j=0, ctr=0, ctr2=0, tmp[100], k, cv=0;
int vowelsCount[100]; //keeps track of number of vowels in each word

printf("Enter statement: ");
gets(x);

for(i = 0; i < 100; ++i) vowelsCount[i] = 0;
i = 0;
while (i<strlen(x))
{
if (x[i] !=' ')
{
y[ctr][ctr2++]=x[i];
if (x[i]=='a' || x[i]=='A' || x[i]=='E' || x[i]=='e' || x[i]=='I' || x[i]=='i' || x[i]=='O' || x[i]=='o' || x[i]=='U' || x[i]=='u')
{
++vowelsCount[ctr];
}
}
else
{
tmp[ctr]=ctr2;
ctr++;
ctr2=0;
}
i++;
}
tmp[ctr]=ctr2;
ctr++;
for (i=0;i<ctr;i++)
{
for (j=0;j<tmp[i];j++)
{
printf("%c", y[i][j]);
}
printf("...Vowels : %d\n", vowelsCount[i]);
}
neo012 at 2007-11-9 1:32:36 >
# 27 Re: help me to my case study..
It is used to set the array members of vowelsCount to 0. You may also do this

memset(&vowelsCount[0], 0, 100 * sizeof(int));//memset ( dest, value to set, no of bytes );
kumaresh_ana at 2007-11-9 1:33:31 >
# 28 Re: help me to my case study..
ohh.. thank you again.
neo012 at 2007-11-9 1:34:32 >
# 29 Re: help me to my case study..
No problem!
kumaresh_ana at 2007-11-9 1:35:37 >