| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Senior Member Join Date: Nov 2005 Location: Hong Kong
Posts: 1,154
![]() ![]() ![]() | Simple C questions How do you find if a certain number is an integer or not? I am trying to make a simple C console application, so any help would be appreciated. Also, how do you display a variable, for example a variable called num (also in the same console application)? I really can't find a thing on the web to help me, so I have turned to the programming gurus of namepros. Please help!
__________________ If you're as bored as I am, join me in Fallensword! (I swear, this game is actually pretty fun :P) |
| |
| | THREAD STARTER #2 (permalink) |
| Senior Member Join Date: Nov 2005 Location: Hong Kong
Posts: 1,154
![]() ![]() ![]() | anyone?
__________________ If you're as bored as I am, join me in Fallensword! (I swear, this game is actually pretty fun :P) |
| |
| | THREAD STARTER #3 (permalink) |
| Senior Member Join Date: Nov 2005 Location: Hong Kong
Posts: 1,154
![]() ![]() ![]() | No one knows C?
__________________ If you're as bored as I am, join me in Fallensword! (I swear, this game is actually pretty fun :P) |
| |
| | #4 (permalink) |
| NamePros Legend Join Date: Dec 2005 Location: Philippines - www.Nabaza.com
Posts: 19,785
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | some C guides/references for you: http://www.cppreference.com/ http://www.acm.uiuc.edu/webmonkeys/book/c_guide/ some for variables and characters and integers: http://www.acm.uiuc.edu/webmonkeys/b...html#variables |
| |
| | THREAD STARTER #5 (permalink) |
| Senior Member Join Date: Nov 2005 Location: Hong Kong
Posts: 1,154
![]() ![]() ![]() | thanks, I got displaying the variable working now, but I still can't seem to get any information on checking if a number is an integer or not... Rep added (or would add Rep, except I have to spread it... )!Anyone else have any information?
__________________ If you're as bored as I am, join me in Fallensword! (I swear, this game is actually pretty fun :P) |
| |
| | #6 (permalink) | ||||
![]() Join Date: Jul 2005 Location: Coffs H, Australia
Posts: 3,456
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Well not too experienced in C myself But I think you might be looking for something like this?:
taken from: http://www.cplusplus.com/doc/tutorial/typecasting.htmlHope it helps, Rhett.
__________________ Free Forums / GoDaddy Coupon Codes (NEW DOMAIN!) / Free Arcade Script / <?='Your computer is '.(1?fine:broken).'.'?> | ||||
| |
| | THREAD STARTER #7 (permalink) |
| Senior Member Join Date: Nov 2005 Location: Hong Kong
Posts: 1,154
![]() ![]() ![]() | looks like C++ to me... ah well, I'll give it a try (later, when I have time), although I don't really follow the code. Rep added!
__________________ If you're as bored as I am, join me in Fallensword! (I swear, this game is actually pretty fun :P) |
| |
| | THREAD STARTER #8 (permalink) |
| Senior Member Join Date: Nov 2005 Location: Hong Kong
Posts: 1,154
![]() ![]() ![]() | anybody else have any suggestions?
__________________ If you're as bored as I am, join me in Fallensword! (I swear, this game is actually pretty fun :P) |
| |
| | #9 (permalink) |
| NamePros Member Join Date: May 2006
Posts: 160
![]() | I'm a little confused as in theory, if the datatype of the number is 'int', then naturally you have an int ![]() ????: NamePros.com http://www.namepros.com/showthread.php?t=194796 Where did this number come from? Is your situation something like "I have a double or a float and want to know if it has nothing after the decimal place?" If so... I'd look at casting the number to an int then compare it to the original number. eg. Code: double d = 0; // this is the number you want to check
int i = (int) d;
if ((d - i) != 0) {
// the number had something after the decimal place
} else {
// the number had nothing after the decimal place
} If you have access to math.h, you could try: Code: double d = 0; // this is the number you want to check
if (fmod(d, 1) != 0) {
// the number had something after the decimal place
} else {
// the number had nothing after the decimal place
} |
| |
| | THREAD STARTER #10 (permalink) |
| Senior Member Join Date: Nov 2005 Location: Hong Kong
Posts: 1,154
![]() ![]() ![]() | wow, gee thanks! That looks like EXACTLY what I needed! I'll give it a try! Rep added!
__________________ If you're as bored as I am, join me in Fallensword! (I swear, this game is actually pretty fun :P) |
| |