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: - 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.
You don't need to get rid of return, just write return (*Count); instead of return(Count); so not to return an adress.
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'
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
|
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");
|
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
|
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)
|
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...
| |
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?
|
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,...
|
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;
|
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" );
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |