Hi
How do i use the functions found in string.h to check if a letter is
vowel and a consonant ?
I have this code :
.........
const char vowel[5]="aeiou";
const char consonant[21]="bcdfghjklmnpq rstvwxyz";
while (position<endof file)
{
read(file,&char _read,1);
if (strpbrk(vowel, char_read)!=NUL L)
{
printf("\n vowel ");
}
else if (strpbrk(conson ant,char_read)! =NULL)
{
printf("\n consonant ");
}
printf(" %c",char_read );
pozitia_curenta ++;
}
}
and somehow the strpbrk does not work .. i also tried with several
functions but i haven't got this right so far
thanks
Vali. 5 5561
"ivalki" <iv****@gmail.c omwrote:
How do i use the functions found in string.h to check if a letter is
vowel and a consonant ?
Why are you using those functions? I suggest you use algorithm instead.
#include <algorithm>
bool is_vowel( char c )
{
const char v[11] = "aeiouAEIOU ";
return std::find( v, v + 11, c ) != v + 11;
}
I have this code :
........
const char vowel[5]="aeiou";
const char consonant[21]="bcdfghjklmnpq rstvwxyz";
The above two arrays are missing nulls at the end, and they are missing
the upper case versions of the letters.
while (position<endof file)
{
read(file,&char _read,1);
if (strpbrk(vowel, char_read)!=NUL L)
Probably broke because of the missing null.
Daniel T. wrote:
"ivalki" <iv****@gmail.c omwrote:
How do i use the functions found in string.h to check if a letter is
vowel and a consonant ?
Why are you using those functions? I suggest you use algorithm instead.
#include <algorithm>
bool is_vowel( char c )
{
const char v[11] = "aeiouAEIOU ";
return std::find( v, v + 11, c ) != v + 11;
}
[ snip ]
I would only use an algorithm if I really needed to, and
the use of magic numbers don't really help either :)
bool is_vowel( char c, std::string vowels = "aeiouAEIOU " ) {
return vowels.find_fir st_of( c ) != std::string::np os;
}
Cheers,
Chris Val
Thanks for helping Chris ( Val ) and Daniel T.
"Chris ( Val )" <ch******@gmail .comwrote:
Daniel T. wrote:
"ivalki" <iv****@gmail.c omwrote:
How do i use the functions found in string.h to check if a letter is
vowel and a consonant ?
Why are you using those functions? I suggest you use algorithm instead.
#include <algorithm>
bool is_vowel( char c )
{
const char v[11] = "aeiouAEIOU ";
return std::find( v, v + 11, c ) != v + 11;
}
[ snip ]
I would only use an algorithm if I really needed to, and
the use of magic numbers don't really help either :)
bool is_vowel( char c, std::string vowels = "aeiouAEIOU " ) {
return vowels.find_fir st_of( c ) != std::string::np os;
}
I thought an implementation like that too, but was somewhat concerned
about using a function that creates a string every call in a function
that would likely be used in an inner loop.
Also, your signature allows things like:
if ( is_vowel( c, "!@#$%^&*() " ) )...
Which is, at best, confusing. For your particular implementation, I
suggest a name change to something like "is_one_of" and dump the default
parameter.
Otherwise, I agree with you.
How about a compromise:
bool is_vowel( char c ) {
static const std::string vowels = "aeiouAEIOU ";
return vowels.find( c ) != std::string::np os;
}
Daniel T. wrote:
"Chris ( Val )" <ch******@gmail .comwrote:
Daniel T. wrote:
"ivalki" <iv****@gmail.c omwrote:
>
How do i use the functions found in string.h to check if a letter is
vowel and a consonant ?
>
Why are you using those functions? I suggest you use algorithm instead.
>
#include <algorithm>
>
bool is_vowel( char c )
{
const char v[11] = "aeiouAEIOU ";
return std::find( v, v + 11, c ) != v + 11;
}
[ snip ]
I would only use an algorithm if I really needed to, and
the use of magic numbers don't really help either :)
bool is_vowel( char c, std::string vowels = "aeiouAEIOU " ) {
return vowels.find_fir st_of( c ) != std::string::np os;
}
I thought an implementation like that too, but was somewhat concerned
about using a function that creates a string every call in a function
that would likely be used in an inner loop.
Also, your signature allows things like:
if ( is_vowel( c, "!@#$%^&*() " ) )...
Which is, at best, confusing. For your particular implementation, I
suggest a name change to something like "is_one_of" and dump the default
parameter.
Otherwise, I agree with you.
How about a compromise:
bool is_vowel( char c ) {
static const std::string vowels = "aeiouAEIOU ";
return vowels.find( c ) != std::string::np os;
}
In fact, I was going to offer such an alternative right after
I posted, but was at work and had no time left to post back.
Having said that..., I agree with you're comments in full! :)
Cheers,
Chris Val This thread has been closed and replies have been disabled. Please start a new discussion. 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: Prof.Stanley |
last post by:
Hello all, please i am trying to write a program that recieves a string
from user and counts double vowels.I have a problem particularly in the
way to input the string,below is my code please will somebody help me
correct any syntax or semantic error or any proposition.
Thanks.
|
by: Jayson Davis |
last post by:
Say I have a string read from a configuration file.
searchfor <tab> Needle\n\n
Where I want to search for the word "Needle" with two linefeeds. Now
when I read it from the file, it hasn't converted the linefeeds into
characters. Is there a function to do that or do I need to write it myself?
|
by: gxs |
last post by:
I'm creating a program to convert a .dat file from English to pig Latin under the following rules:
1. If the word begins with a vowel, add "-way" to the end.
2.If the word doesn't begin with a vowel, add a "-" to the end, then put the first letter after the "-" and so on until the first letter of the word is a vowel, then add "ay" to the end after the letters you added.
3. y is considered a vowel
4.If a word has no vowels at all,...
|
by: Ron |
last post by:
I am getting an error Option strict on disallows implicit conversion
from string to long
I get it for this code
iStartPosition = InStr(iStartPosition + 1, RichTextBox1.Text, "A" Or
"a"
the "A" and "a" are underlined in blue. How can I fix this?
| |
by: dany11gr |
last post by:
Hi,
I'm actually new to this site. So i don't know if i could ask directly about how to write any code. I'm working on this code to output vowless string from the user- input line of text. For example, input "word" and want the output to be "wrd"
This is what i have so far...
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
|
by: teriwalker |
last post by:
import java.util.*;
import java.lang.Character.*;
public class IsVowel
{
static char vowels = { 'a', 'e', 'i', 'o', 'u', 'y' };
public static boolean isVowel(char s)
{
|
by: Doegon |
last post by:
Hi
i need help with writing a method that takes in a string of characters and counts the syllables in the string.
the method should not count chacter 'e' if its the last character in the string and by definition a syllable is vowel or a pair of adjacent vowels(a,e,o,i,u),the adjacent vowels count as one.
so my problem is identifying that the two adjacent characters are vowels.how can i tackle this?
thank you.
|
by: lpc403 |
last post by:
New to Java (and programming in general) and trying to accept a sentence from the command line to count the consonants, vowels, and punctuation. What code do I need to perform the following?
1) Seperate each word so that it runs through the swtich to perform a count
2) Loop back to get each subsequent word until the sentence ends
I have it working when setting the sentence as a varible and reading it. Not sure how to take this next...
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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: 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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |