473,797 Members | 3,079 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

counting vowels in string (c language)

5 New Member
Hey everyone,

I am supposed to write a program that counts the number of vowels in string of characters.
It must include "Struct counter_t (it must be declared as in the code i've written)" and function "int CountVowels (IN text[], OUT Count)". the OUT parameter must be of type counter_t. I've written the code but it doesn't seem to work. Can someone help me please???

-------------------------------------------------------------------------------------------------------------
#include <stdio.h>

typedef struct {
int a;
int e;
int i;
int o;
int u;
}counter_t;

int CountVowels (char text[], counter_t Count);

int main ()
{
char text[100];
counter_t Count;
Count.a = 0;
Count.e = 0;
Count.i = 0;
Count.o = 0;
Count.u = 0;
printf ("Text\n");
gets(text);
CountVowels(tex t, Count);
printf("a = %d\n", Count.a);
printf("e = %d\n", Count.e);
printf("i = %d\n", Count.i);
printf("o = %d\n", Count.o);
printf("u = %d\n", Count.u);
fflush (stdin);
getchar ();
return 0;
}

int CountVowels (char text[], counter_t Count)
{
int i;
for (i = 0; text[i] != '\0', i++)
{
switch(text[i])
{
case 'a': Count.a++; break;
case 'e': Count.e++; break;
case 'i': Count.i++; break;
case 'o': Count.o++; break;
case 'u': Count.u++; break;
}
}
return (Count);
}
------------------------------------------------------------------------------------------------------
Sep 12 '08 #1
12 10046
boxfish
469 Recognized Expert Contributor
Hi,
There are two things that I see wrong offhand. Since CountVowels returns a Count object, its return type has to be Count, not int. Make it:
Expand|Select|Wrap|Line Numbers
  1. Count CountVowels (char text[], counter_t Count);
Also, your CountVowels function does not count uppercase vowels. The tolower function from ctype.h should be useful for that.
Hope this helps.
Sep 12 '08 #2
ashpats
5 New Member
well i've improved my code a bit. but it still has some problems. (the program doesn't have to count upper case vowels).

#include <stdio.h>

typedef struct {
int a;
int e;
int i;
int o;
int u;
}counter_t;

counter_t CountVowels (char text[], counter_t* Count);

int main ()
{
char text[100];
counter_t Count;
Count.a = 0;
Count.e = 0;
Count.i = 0;
Count.o = 0;
Count.u = 0;
printf ("Text\n");
fgets(text, sizeof text, stdin);
Count = CountVowels(tex t, Count);
printf("a = %d\n", Count.a);
printf("e = %d\n", Count.e);
printf("i = %d\n", Count.i);
printf("o = %d\n", Count.o);
printf("u = %d\n", Count.u);
getchar ();
return 0;
}

counter_t CountVowels (char text[], counter_t* Count)
{
int i;
for (i = 0; text[i] != '\0'; i++)
{
switch(text[i])
{
case 'a': Count->a++; break;
case 'e': Count->e++; break;
case 'i': Count->i++; break;
case 'o': Count->o++; break;
case 'u': Count->u++; break;
}
}
return (Count);
}
Sep 12 '08 #3
Laharl
849 Recognized Expert Contributor
What problems are you encountering? We're neither telepathic nor C compilers (either would be kinda cool, just look at code and BOOM! it's compiled), so if you can post what's going wrong, we can help you.

Also, please surround your code with [code] tags. It makes it much easier to read.
Sep 12 '08 #4
ashpats
5 New Member
[Count = CountVowels(tex t, Count);] error C2440: 'function' : cannot convert from 'counter_t' to 'counter_t *'

and
[return (Count);] error C2440: 'return' : cannot convert from 'counter_t *' to 'counter_t'
Sep 12 '08 #5
gpraghuram
1,275 Recognized Expert Top Contributor
[Count = CountVowels(tex t, Count);] error C2440: 'function' : cannot convert from 'counter_t' to 'counter_t *'

and
[return (Count);] error C2440: 'return' : cannot convert from 'counter_t *' to 'counter_t'

This line is the issue.
Count = CountVowels(tex t, Count);
Pass the Count by its address like
Count = CountVowels(tex t, &Count);


Raghu
Sep 12 '08 #6
newb16
687 Contributor
Hi,
There are two things that I see wrong offhand. Since CountVowels returns a Count object, its return type has to be Count, not int.
No. Assignment specification reads "int vowelcount(IN text, OUT count);"
So second arg needs to be count* .
Sep 12 '08 #7
Banfa
9,065 Recognized Expert Moderator Expert
If you are tassing a pointer to counter_t into the function CountVowels that is the location of the structure to store the results in (and therefore provides a channel to pass the results back to the calling code) then ask yourself what is the purpose of the return value of the function CountVowels, what could it return, what does it need to return?

From that decide what type it should be and change your function accordingly.
Sep 12 '08 #8
ashpats
5 New Member
well i've changed few lines:

Count = CountVowels(tex t, Count); to Count = CountVowels(tex t, Count*);

counter_t CountVowels (char text[], counter_t* Count) to
void CountVowels (char text[], counter_t* Count)

end got rid of 'return'. but now i get a syntax error:
Count = CountVowels(tex t, Count*); error C2059: syntax error : ')'
Sep 12 '08 #9
Laharl
849 Recognized Expert Contributor
If you don't return anything from the function, you can't set its return value to a variable, now can you?
Sep 12 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

11
1924
by: Prof.Stanley | last post by:
hello , i ma new in this group and writing over the fact that i have a small project at hand,i am writing a program which can permit the input of a text of arbitary lenght,and the number of double vowels must be determined. Output:frequency of each double vowel ,must be dtermined. e.g. Later ,we will see you again OUTPUT:1xee,1xou,1xai.
3
1603
by: Peter K | last post by:
Hi I am looking for an elegant method for splitting strings with the following format into its separate parts: <id><language><version> id is always 32 characters long; language is a representation of language/locale (eg. "en" or "da-DK"); version is always a number (eg. "3" or "17" or "665");
2
12070
by: Kelly B | last post by:
I tried to write a code which would reverse the order of words in a given string. I.e if Input String=The C Programming Language Output String=Language Programming C The Here is the code ..but it seems a bit "bloated" as i need an extra array of same size of the original string
2
2624
by: charlesbritto | last post by:
A C++ program for counting individual string in a text file using file handling functions., for ex: if the text file contains, am a boy,am studying +2,am from chennai Now the result shoud be as 3 bcaz ("am" presenting 3 times)
1
2431
by: powerej | last post by:
I have gotten the part of counting how many words are in the string, but the vowels just seem alien to me. Ive tried so many things but never close to a correct answer. I know I need to use charAt() and length() some nested loops with do while and for, but cant seem to get headed in the right direction. Also when i click the cancel button my program is suppose to end and tell you how many lines were entered, a count of vowels from all lines...
5
4349
by: Cylix | last post by:
Is there any existing method in VB.NET or any 3-third party function can find out the language in a string? Let say, isChinese? isFrench?
2
4132
by: Geneses | last post by:
Hi! I'm using Eclipse as an IDE, I need to code a program where users enter a string and it computes the count for each vowel, and how many words are in the string. Users can do as many strings as they want until they hit cancel. This is what I have so far: import javax.swing.*; public class Program { //Open Class public static void main(String args) { //Open Main String input, output; //Holds input and output. int aCount = 0,...
6
4289
by: HypeBeast McStreetwear | last post by:
Hi I'm supposed to be writing a program that counts in a given text, the words that contain at least three different vowels (a,e,i,o,u) For my test run I have to use "unquestionably", but I can't anything to work. Here's what I have so far. #include <iostream> #include <string> #include <cstring> using namespace std;
2
4117
by: djpaul | last post by:
Hello, I have made a script so the user can change the language of the site. But of some reason the user has to click twice on the flag before it changes. On page load he doesn't see the language (sets it to the default). This is my code: Index.php: <? include( "inc/functions.php" );
0
10468
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10245
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9063
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7559
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5458
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4131
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.