|
|
|
My understanding of "isdigit()" is that it takes a parameter and checks whether it's a digit. It will then return true or false depending on what the parameter value turns out to be.
Fair enough, I constructed my "if" statement based on this understanding, only to find out that the opposite is what's happening. Here's some code.
string str;
int nbr = atoi(str.c_str());
...
if(isdigit(nbr))
else
Prior to reaching the "if" statement, "nbr" is assigned a numeric value (by making sure that 'str' is numeric), but instead of doing the digital processing, it does the error reporting routine. Interestingly, if I were to test for "!isdigit(nbr), it does the digital processing. (But then why would it do the digital processing if nbr is not numeric?)
Why is this? Am I using "isdigit()" wrongly?
Thanks for any insight.
William
Fortes in fide et opere!
|
|
|
|
|
isdigit() takes a character value, not an integer.
"Sucks less" isn't progress - Kent Beck [^]
Awasu 1.1.4 [^]: A free RSS reader with support for Code Project.
|
|
|
|
|
Then how come <ctype> and <ctype.h> defines it as:
int isdigit(int c);
William
Fortes in fide et opere!
|
|
|
|
|
Because passing char's as parameters tends to cause problems.
Just try it
"Sucks less" isn't progress - Kent Beck [^]
Awasu 1.1.4 [^]: A free RSS reader with support for Code Project.
|
|
|
|
|
OK! I did try it. I substituted 'nbr' for a 'char' value and ran the program, and even though I entered a numeric value, the program crashed!
It didn't crash when I was using 'nbr' instead.
William
Fortes in fide et opere!
|
|
|
|
|
isdigit() tests whether a character is a digit. Pass in a char , not an int . The parameter is defined as an int because all the functions that operate on characters are defined that way. Yes, it's weird. (The reason is that EOF is -1, which is outside the range of char , so they had to use a larger type instead.)
--Mike--
Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Laugh it up, fuzzball.
|
|
|
|
|
I need to convert CSV file into an Excel Sheet. Can I have suggesstions or article where can I get the information.
Thanks in advance
Warm Regards,
KKR
|
|
|
|
|
Assuming through code, just use the Excel COM object and tell it to open the csv file. Then tell it to save as Excel file.
|
|
|
|
|
There are two ways:
1.Using ODBC Excel driver which is available on all Windows PC's even without M$ Office installed, neither on your nor your user's PC.
For an example see this:
http://www.codeproject.com/database/excel_odbc_write.asp[^]
2.Using Excel automation, requires Office both on you and your user's PC
See Adam's message above, and MSDN for Office automation.
Peter Molnar
|
|
|
|
|
Hi lads, i have a challenging question for you all:
I'm using ReadDirectoryChangesW to monitor the file usage in the system.
Then i'm using the CFile constructor to (GetLenght, GetStatus, GetFilePath, etc) extract the file's informations.
I need a way to find the file physical address... address on the hardisk!!!
Your help is very much appreciated....
Ade
|
|
|
|
|
ReadDirectoryChanges uses a FILE_NOTIFY_INFORMATION struct to give you the paths of changed files.
FILE_NOTIFY_INFORMATION fni[100];
while (ReadDirectoryChangesW(...,&fni,...)
{
if (fni[0].Action == ...added || fni[0].Action == ...removed || fni[0].Action == ...Modified)
DoSomethingWhenAddedRemovedOrModified(..);
for (int i = 0; !fni[i].NextEntryOffset; i++)
ShowFileName(fni[i].FileName);
}
Peter Molnar
|
|
|
|
|
Hi peter,
thanks for your help, i know how to find a file path,
i just want to know how to find the files physical location / address in main memory (hardisk)!!! example
Sector 123542 Lenght: 3 Block ( or whatever unit: cluster / sector / block / etc )
anyone else ??? !!!!
|
|
|
|
|
hi,
i don't believe you'll ever be able to do that with just ring3 priviledges.
just OSs have access to such data.
Phil
|
|
|
|
|
Hi,
Maybe this is a stupid question, but I'm a rookie .
I'm working on a Chat-Server and got it working with threads;
<br />
void __fastcall TMain::ServerSocketGetThread(TObject *Sender,<br />
TServerClientWinSocket *ClientSocket, TServerClientThread *&SocketThread)<br />
{<br />
SocketThread = new TMyServerThread(false, ClientSocket);<br />
}<br />
<br />
<br />
void __fastcall TMyServerThread::ClientExecute(void) <br />
{<br />
while (!Terminated && ClientSocket->Connected)<br />
{<br />
try<br />
{<br />
TWinSocketStream *pStream = new TWinSocketStream(ClientSocket, CLIENTWAITTIME);<br />
<br />
try<br />
{<br />
etc.<br />
...but now I want to 'assign' each incoming Client... so like in a list. Also want to show all connected Clients in a ListView.
I know how to send text/a buffer in a thread, but how can I send to a specific(assigned) Client from the 'Main' form/api?!
Am a bit lost .
Roland(BE).
|
|
|
|
|
if i understand u right u need to keep a list of users with ip addresses when they connect
then u can route msgs to specific users
or did i misunderstand completely?
"there is no spoon" biz stuff about me
|
|
|
|
|
Hi !
This is I guess a stupid question, but I'm wondering how in C++ I can round a float :
if I do :
int i=1.6;
I get : i=1;
but I'd like instead i=2 !
Is there an easy way to do this, or do I have to do the work by myself ?
Thanks !
Jerome
|
|
|
|
|
Use ceil(), from math.h.
HTH
Ryan
|
|
|
|
|
Ryan Roberts wrote:
Use ceil(), from math.h.
Well, the result is not the one expected.
I'll try to make myself clear :
the float number 1.6 should be rounded to 2
the float number 1.5 should be rounded to 2
the float number 1.2 should be rounded to 1
the ceil() function always round to the upper integer.
I cannot find the function which will round my float number correctly according to mathematic rules. ceil() and floor() are not doing what I want !
Jerome
|
|
|
|
|
Must listen to question, this is the reason I was always crap at maths.
You actualy want to call.. round().. damn cryptic function names
HTH
Ryan
|
|
|
|
|
Ryan Roberts wrote:
You actualy want to call.. round()..
But it doesn't exists ! I try to find it in the MSDN, but it is not.....
mmmhh it looks like I'll have to write my own !
Jerome
|
|
|
|
|
// this rounds to nearest whole number
int round = (int)((val < 0) ? (val - 0.5) : (val + 0.5));
Roger Allen - Sonork 100.10016
If your dead and reading this, then you have no life!
|
|
|
|
|
Its in stlport. Guess they have to be different
Try #define round(x) floor(x+0.5)
Ryan.
|
|
|
|
|
Try this one:
<br />
double a=1.6; <br />
int i = static_cast<int>(a+0.5);
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|