473,320 Members | 1,868 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,320 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 7373
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.