473,806 Members | 2,929 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
12 10047
boxfish
469 Recognized Expert Contributor
I see that you were right that the function was supposed to return an int. Sorry about that. I think the Count parameter is supposed to be passed by reference so you can modify it in the function but not return it, and the int the function returns is the total number of vowels; the sum of all the variables in the struct. So the prototype would be:
Expand|Select|Wrap|Line Numbers
  1. int CountVowels (char text[], counter_t* Count);
And at the end of the function, you add up all the individual vowel counts and return that.

Here's a link to a reference for the tolower function.
Sep 12 '08 #11
curiously enough
79 New Member
You don't need to get rid of return, just write return (*Count); instead of return(Count); so not to return an adress.
Sep 13 '08 #12
ashpats
5 New Member
thanx guys. i finally finished it.
the line
Count = CountVowels(tex t, Count);
was the problem. i simply changed it to
CountVowels(tex t, &Count);
and it appears to be workin'
Sep 16 '08 #13

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
12072
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
2625
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
2432
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
4351
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
4134
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
4291
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
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10369
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...
1
10372
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10110
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
9187
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
7650
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
5546
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...
1
4329
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
2
3851
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.