Could I get some help as to understanding why I am not getting a result
I expect.
#include <stdio.h>
#include <ctype.h>
int main (){
int i,j,k,c;
i=9;
c='A';
j=isdigit(9);
k=isdigit('A');
printf("\nThe value of \"isdigit(%d )\" is %d", i,j);
printf("\nAnd the value of \"isdigit('%c') \" is %d\n", c,k);
return 0;
}
Output:
The value of "isdigit(9) " is 0
And the value of "isdigit('A ')" is 0
Expected:
The value of "isdigit(9) " is 0
And the value of "isdigit('A ')" is 1 10 5907
mdh wrote:
Could I get some help as to understanding why I am not getting a result
I expect.
#include <stdio.h>
#include <ctype.h>
int main (){
int i,j,k,c;
i=9;
c='A';
j=isdigit(9);
k=isdigit('A');
printf("\nThe value of \"isdigit(%d )\" is %d", i,j);
printf("\nAnd the value of \"isdigit('%c') \" is %d\n", c,k);
return 0;
}
Output:
The value of "isdigit(9) " is 0
And the value of "isdigit('A ')" is 0
Expected:
The value of "isdigit(9) " is 0
And the value of "isdigit('A ')" is 1
'A' is not a digit
9 is not a digit
'9' is a digit
On Oct 6, 2:02 pm, "mdh" <m...@comcast.n etwrote:
Could I get some help as to understanding why I am not getting a result
I expect.
#include <stdio.h>
#include <ctype.h>
int main (){
int i,j,k,c;
i=9;
c='A';
j=isdigit(9);
k=isdigit('A');
printf("\nThe value of \"isdigit(%d )\" is %d", i,j);
printf("\nAnd the value of \"isdigit('%c') \" is %d\n", c,k);
return 0;
}Output:
The value of "isdigit(9) " is 0
And the value of "isdigit('A ')" is 0
Expected:
The value of "isdigit(9) " is 0
And the value of "isdigit('A ')" is 1
Do you consider 'A' as a hexadecimal digit? If so, use function
isxdigit() instead of isdigit().
'A' is not a digit
9 is not a digit
'9' is a digit
it's getting late...thank you
Answer; Since c is a integer variable,when we try to store the
charecter in the integer variable Ascii value of that charecter is
stored in the variable,since Ascii value of the charecter is also digit
hence the isdigit()
function returns true
j=isdigit(9);
k=isdigit('A');
Hi,
The isdigit() function takes an argument of character type or EOF and
it return non zero value if
the passing argument is characters '0' , '1' . . . '9' else it returns
zero.
Now consider your actual out put.
1. The first part of the out put is true as you have supplied wrong
argument i.e. a integer
insite of supplying char.
2. Second part is also true. No need to explain.
Regards,
Shafi
"the difficult we do immediately, the impossible takes a little
longer", [US Army
"shafi" <sh*********@gm ail.comwrites:
>j=isdigit(9) ; k=isdigit('A') ;
The isdigit() function takes an argument of character type or EOF and
it return non zero value if
the passing argument is characters '0' , '1' . . . '9' else it returns
zero.
More precisely,
... the argument is an int, the value of which shall be
representable as an unsigned char or shall equal the value of the
macro EOF. If the argument has any other value, the behavior is
undefined.
This is an important distinction. Something like this:
char c = some_value;
isdigit(c);
can invoke undefined behavior if (1) plain char is signed, and (2) the
value of c is negative (and not equal to EOF). For arguments other
than EOF, it's often a good idea to cast the argument:
char c = some_value;
isdigit((unsign ed char)c);
(This is one of the few cases where a cast is actually a good idea.)
Or, in this case, you could avoid the cast by changing the declaration
of c:
unsigned char c = some_value;
isdigit(c);
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
On Fri, 2006-10-13 at 22:22 -0700, shafi wrote:
j=isdigit(9);
k=isdigit('A');
Hi,
The isdigit() function takes an argument of character type or EOF and
it return non zero value if
the passing argument is characters '0' , '1' . . . '9' else it returns
zero.
isdigit(c) function takes an argument of type int that must be in the
range of unsigned char or EOF. It returns nonzero on '0'...'9',
otherwise returns 0.
Now consider your actual out put.
1. The first part of the out put is true as you have supplied wrong
argument i.e. a integer
insite of supplying char.
Wrong. 9 is in the range of unsigned char, and therefore is perfectly
valid. Whether the expression evaluates to true or not depends on the
charset.
2. Second part is also true. No need to explain.
Wrong. 'A' is not a digit.
--
Andrew Poelstra <http://www.wpsoftware. net/projects/>
Andrew Poelstra wrote:
>
On Fri, 2006-10-13 at 22:22 -0700, shafi wrote:
j=isdigit(9);
k=isdigit('A');
Hi,
The isdigit() function takes an argument
of character type or EOF and
it return non zero value if
the passing argument is characters
'0' , '1' . . . '9' else it returns zero.
isdigit(c) function takes an argument of type int that must be in the
range of unsigned char or EOF. It returns nonzero on '0'...'9',
otherwise returns 0.
Now consider your actual out put.
1. The first part of the out put is true as you have supplied wrong
argument i.e. a integer
insite of supplying char.
Wrong. 9 is in the range of unsigned char, and therefore is perfectly
valid. Whether the expression evaluates to true or not depends on the
charset.
It doesn't depend on the char set.
isdigit is one of the ctype functions
that does not have locale specific behavior.
--
pete
pete <pf*****@mindsp ring.comwrites:
Andrew Poelstra wrote:
[...]
>Wrong. 9 is in the range of unsigned char, and therefore is perfectly valid. Whether the expression evaluates to true or not depends on the charset.
It doesn't depend on the char set.
isdigit is one of the ctype functions
that does not have locale specific behavior.
The value of isdigit(9) depends on the character encoding, which can
vary from one implementation implementation to another. (I don't know
whether "char set" is the right term for this.)
I believe it returns 0 on all existing implementations , but 9 could
theoretically be the encoding for some digit (but it can't be the
encoding for '9', since the digits are contiguous and '\0' can't be a
digit).
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: James Gregory |
last post by:
I read that the argument to isdigit() can be "an integer whose value is
representable as an unsigned char, or the value of the macro EOF.". This
seems to say that it should work for values greater than 127. And in
Linux + GCC, it does - values between 128 and 255 are false.
However, in Windows XP + GCC (at least some) values between 128 and 255
come out as true for isdigit. Someone suggested this may be because
Windows uses a different...
|
by: Carramba |
last post by:
hi!
I am trying to confirm if input is digit, so I thought it would by easy to
do it with with isdigit() funktion,
but how do I pass arrays to it if the imput is more then 1 sign?
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
int main(){
|
by: Per Rollvang |
last post by:
Hi All!
I have a problem with hex strings when using Char.IsDigit().
The hex strings(i.e. a CRC32 checksum) get a false result for letters A-F...
MSDN tell me that:
Indicates whether a Unicode character is categorized as a
decimal digit or hexadecimal number.
|
by: Jefe |
last post by:
Hi Group
Could you please explain to me what's the difference between Chars.IsDigit
and Chars.IsNumber?
Regards,
|
by: skneife |
last post by:
Doeas any know the simplest way for create this type of function:
bool result = IsDigit(string s);
Sam
| |
by: MooMaster |
last post by:
N00b question alert! I did a search for isdigit() in the group
discussion, and it didn't look like the question had been asked in the
first 2 pages, so sorry if it was...
The manual documentation says:
"isdigit( )
Return true if all characters in the string are digits and there is at
least one character, false otherwise.
For 8-bit strings, this method is locale-dependent. "
|
by: bozo789 |
last post by:
Hi Forum,
First let me begin by stating I am a student and have read the proper posting procedure concerning students. I am a begginer learning with the Miracle C Work Bench. I know my code is probably doing everything the long way, and there are more proficient ways to write my program, but like I said, I am just learning this foreign language. I'll get there!! (smiling)
Here is my problem, In my code I am trying to both verify that a...
|
by: khaichiew85 |
last post by:
im having a program.I want it to check if it is a character or integer is entered
where shall i put the isDigit and how to use?i put it as highlighted below but got error.
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
int is_prime( int input, int z);
int main (void)
|
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: 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: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |