473,385 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

limited range of data type

if (a[n] == 'a' || a[n] == 'e' || a[n] == 'i' || a[n] == 'o' || a[n] == 'u' || a[n] == 'w' || a[n] == 'y' || a[n] ==
'h' || a[n] == 'space' || a[n] == '-'){

Basically im asking the program to do something if it comes across any of the above characters, problem seems to be with the space. Ive tried ' ' which doesnt work, tried the unicode for a space but it said its only supported in c++, so how could I solve the error " warning: comparison is always false due to limited range of data type"? Help appreciated!
Nov 15 '06 #1
14 7378
Banfa
9,065 Expert Mod 8TB
a[n] == 'space'

should be

a[n] == ' '

I know you say this doesn't work but since you don't say how it doesn't work and I know that this is the correct test for a space character I can only assume that whatever is causing it to not work is either a problem else where in your code or a problem in the input data to the program.

however that only checks for the space character, perhaps what you have is a tab character in the input data? so you could also try

isspace(a[n]);

defined in ctype.h which checks for all whitespace characters space, tab, new line and carridge return.

or you can check for just tabs as well with

a[n] == '\t'
Nov 15 '06 #2
When using ' ' the output is incorrect. The program takes two words "For Example" and encodes them (much like the soundex algorithm). The output is fine if I use "For-Example" but taking away the '-' and leaving a space gives the wrong output.
Nov 15 '06 #3
Banfa
9,065 Expert Mod 8TB
Again since you are failing to give detail, the expected output and the actual output, and you have failed to give your code I can not comment. All I can say is that

a[n] == ' '

is the correct test for a space.
Nov 15 '06 #4
int removevowels(char a[size], char b[3])
{
int i = 1;
int n = 1;
int c;
int x = strlen(a);
b[0] = a[0];

while (n <= x)
{
if (a[n] == 'a' || a[n] == 'e' || a[n] == 'i' || a[n] == 'o' || a[n] == 'u' || a[n] == ' ' || a[n] == '-'){
}else
{
b[i] = a[n];
i++;
}
n++;
}
c = strlen(b);
return 0;
}

The function is meant to remove all vowels, hyphens and spaces from a string.
Nov 15 '06 #5
Banfa
9,065 Expert Mod 8TB
Well that works fine for me

Expand|Select|Wrap|Line Numbers
  1. int main(void)
  2. {
  3.     char string[] = "For Example";
  4.     char out[30];
  5.  
  6.     removevowels(string, out);
  7.  
  8.     cout << '"' << string << '"' << " to " << '"' << out << '"' << endl;
  9.  
  10.     return 0;
  11. }  
  12.  
output

Expand|Select|Wrap|Line Numbers
  1. "For Example" to "FrExmpl"
like I said it's probably an error in the rest of your code somewhere or the input data.
Nov 15 '06 #6
input

Von Dutch

output

Vn

it doesnt seem to bother with the second word.
Nov 15 '06 #7
Banfa
9,065 Expert Mod 8TB
No I get the output

Expand|Select|Wrap|Line Numbers
  1. "Von Dutch" to "VnDtch"
and I am using your removevowels function exactly as you have posted it (i.e. I just copied and pasted it into my program).

As I have already said twice the error must be in another part of your program code or related to the interaction between the rest of your code and this function.
Nov 15 '06 #8
Ive commented out all the other code
Nov 15 '06 #9
r035198x
13,262 8TB
No I get the output

Expand|Select|Wrap|Line Numbers
  1. "Von Dutch" to "VnDtch"
and I am using your removevowels function exactly as you have posted it (i.e. I just copied and pasted it into my program).

As I have already said twice the error must be in another part of your program code or related to the interaction between the rest of your code and this function.
How are you getting the input string? It seems you are reading only one word at a time i.e reading the input until a space is returned so that you only have one word in the end.
Nov 15 '06 #10
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define size 30


int removevowels(char a[size], char b[3])
{
int i = 1;
int n = 1;
int c;
int x = strlen(a);
b[0] = a[0];

while (n <= x)
{
if (a[n] == 'a' || a[n] == 'e' || a[n] == 'i' || a[n] == 'o' || a[n] == 'u' || a[n] == ' ' || a[n] == '-'){
}else
{
b[i] = a[n];
i++;
}
n++;
}
c = strlen(b);
return 0;
}

int main()

{
char name [size];
char removevowelsname [3];
printf("Surname:");
scanf("%s", &name);
removevowels(name, removevowelsname);
printf("Encoded: %s\n", removevowelsname);
return 0;
}


That is everything that is uncommented.
Nov 15 '06 #11
Banfa
9,065 Expert Mod 8TB
char removevowelsname [3];

This is the problem, you have only allocate 3 bytes of memory to hold the converted string but "VnDtch" is 7 bytes.

Like I said the problem was in a piece of code that you had not posted.
Nov 15 '06 #12
char removevowelsname [size];

taking the predefined limit of 30

output

Vn
Nov 15 '06 #13
r035198x
13,262 8TB
char removevowelsname [3];

This is the problem, you have only allocate 3 bytes of memory to hold the converted string but "VnDtch" is 7 bytes.

Like I said the problem was in a piece of code that you had not posted.
use a char*
Nov 15 '06 #14
Banfa
9,065 Expert Mod 8TB
use a char*
Certainly it would be more usual to declare the function removevowels with char * parameters but the way they are declared the type of the parameters to removevowels are char * even though it may not be obvious, because you can't pass an array as a function parameter.

However the other mistake that is causing the error is in

scanf("%s", &name);

Mistake 1 (really minor)
&name, name is already a pointer and the & is not required.

Mistake 2 (the cause of the problem
scanf uses space as a string delimiter so in the string "Von Dutch" "Von" gets assigned to name and "Dutch" gets discarded as not required (or left in the input buffer).

scanf is an unsafe function to use anyway with %s due to the risk of buffer overruns, replace it with

fgets(name, sizeof name, stdin);

which reads a whole line into name and it all starts working.


But you do still need to resize the array removevowelsname
Nov 15 '06 #15

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

Similar topics

1
by: MLH | last post by:
In an Access 97 form, I have a textbox control with the following code that runs AfterUpdate... Option Compare Database Option Explicit Private Sub UNIXdate_AfterUpdate() Me!RealDate =...
6
by: LordHog | last post by:
Hello all, My lead wants to implement a data range monitor for a project that we are coding. Basically it performs a boundry checking that will take three parameters. I am/was trying to...
2
by: Dave | last post by:
hello... I wrote a marco for saturation. #define clip(x) (char)(x)<0?0:((x)>255?255:(x)); and use this marco in the program like this... char tmp=(char)clip((unsigned_int_16)(tmp1+tmp2)); ...
4
by: Todd Perkins | last post by:
Hello all, surprisingly enough, this is my first newsgroup post, I usually rely on google. So I hope I have enough info contained. Thank you in advance for any help! Problem: I am getting...
3
by: George | last post by:
Sub ExcelToListBox() Dim xRange As Object Dim ary Dim xValue As String xRange = oXL.Range("A1:A9") 'has letters A-H ary = xRange.value xValue = ary(3, 1) 'xValue = C...
21
by: matko | last post by:
As far as I can see, there is no similar way of replicating the following Delphi-code in C#... Is that true? type IntRange = -5..5; CharRange = 'a'..'z'; TColors = (Red, White, Green, Blue,...
4
by: amy | last post by:
Hi to Everyone: I need big help on how to query the Age range. Age field is text data type, Age are from 0 wk, 1 wk, 2wk.....up to 15 wk. Try to set up query in Query desing mode with criteria is...
2
by: a1drich | last post by:
smartCryptor.cpp: In function `void Char2Hex(unsigned char, char*)': smartCryptor.cpp:188: warning: comparison is always true due to limited range of data type void Char2Hex(unsigned char...
1
by: assgar | last post by:
Hi I need help. I know what I want to accomplish, but I do not know how to do it. WHAT I NEED HELP ACCOMPLISHING: How to do I insert data into a table for a date range of...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.