|
atoi() would return 0 for "cars 5" since it found no numbers before it found a non-number. In other words, it converts all numbers up to the first non-number encountered.
Differentiating between the return values of atoi("0") and atoi("T") sounds like a design issue. What is the format of the incoming data?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
The data has been writeString--ed to a file with a %d format.
So I read it back in later and want to make sure someone didnt inadvertently change what should be a numerical entry in the input file, into a alphabetical entry.....so I was going to use atoi to check the readstring-ed CString......
Thanks,
ns
|
|
|
|
|
So your file should look like:
123
456
004
991
...
and you want to ensure that someone hasn't changed it to:
07b
1c8
004
3df
...
Is that an accurate assesment? If so, you'll need to employ ReadString() to read each line from the file and parse the data yourself, something like:
CString strLine;
while (...)
{
file.ReadString(strLine);
if (! IsAllNumbers(strLine))
AfxMessageBox(...);
}
bool IsAllNumbers( LPCSTR lpszData )
{
while ('\0' != *lpszData)
{
if (isdigit(*lpszData))
lpszData++;
else
return false;
}
return true;
}
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Thank you so much! Its exactly what the scenario is and your resolution works really well! I appreciate having this snippet of code to "import" into my project.
ns
|
|
|
|
|
atoi starts translation first by removing seperator characters(like space) from the string, looking for the first character. if it is a digit, it starts translating it into an integer, but if not, it returns zero.
you can use it like this:
LPSTR ss="4 cars";
int x=atoi(ss);
if(x==0 && strcmp(ss,"0")){
// the input is probably not a real zero,
// it's an error
}
|
|
|
|
|
Actually it would be better to use strncmp instead of strcmp because then you specify the number of characters to compare so it would return correctly if the string contained "0 cars" also you would want to trim out the spaces in the string first before the compare in case you had a string " 0 cars" so that it would return correctly as well.
|
|
|
|
|
Appreciate the explanation and the nifty way to handle it.
Many thanks,
ns
|
|
|
|
|
I usually use isdigit() to test for such things.
Calling a function that carries out an operation that you have no intent on using just to see if it returns an error isn't typically considered good design.
|
|
|
|
|
For example:
'D:\Documents and Settings\Grrrr\My Documents'
In VC++6.0, which function or API or Class can do this?
Thanks a lot...
|
|
|
|
|
use SHGetSpecialFolderPath
|
|
|
|
|
This method is the simplest method??
Just now, I have read this function in MSDN.
I found it use Shell...
I thought there have a simple mothod, I thought we can get the path-name
direct, use a API. as 'GetSystemDirectory'.
I'm sorry.perhaps i am wrong.
|
|
|
|
|
|
HEY LOOK I THE FAQ SECTION I SAW THIS THERE GOOD LUCK
H43K4Z
|
|
|
|
|
I'm still a green horn in the area of COM and I have some business object classes I want to put in a com server(either DLL or EXE).How do I achieve this using wizards and Compiler COM support(attributes etc.)?
I've been using MFC for some time now.
What would life be without politicians and programmers?
|
|
|
|
|
I think that your topic might be beyond the scope of the forums, but a good place to start is "Beginning ATL 3 COM" ISBN: 1861001207 and "Professional ATL COM Programming" ISBN: 1861001401 if you can still find them. They are a great start and cover using COM and developing COM objects in C++.
|
|
|
|
|
Hi, I've created a server using dialog which listens to any incoming client connections. here, while the server listens, it is blocked in an infinite loop while accepting connections. Now I want the server to create a new thread for every connection with a new client. how can I do this.
Also, I cannot write the thread handler as a member function of a class. how can i do that?
Shenthil
|
|
|
|
|
Shenthil wrote:
Now I want the server to create a new thread for every connection with a new client.
Really? Are you sure you want that many potential threads/connections? Have you considered a thread pool?
Shenthil wrote:
Also, I cannot write the thread handler as a member function of a class. how can i do that?
Use a static member.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
One solution is a non-blocking I/O model. In such a design, a process only needs one or two threads per CPU.
Kuphryn
|
|
|
|
|
hey,
does somebody know how to delete the kernel32.dll ?
Thanks in advance!
|
|
|
|
|
c:\> format c:
--
Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so. (Douglas Adams)
|
|
|
|
|
On all versions of Windows, you can't delete it while Windows is running because it's loaded into every process on the system. There is a way to get Windows to replace a file that's in use when it reboots, but in this case I'm not going to tell you because you're basically intending to break Windows.
Windows 2000, XP and Server 2003 will resist you by copying out of the DllCache, unless Windows File Protection is disabled. Even if it is, the next patch that replaces kernel32.dll will undo what you've done - or the next time that the user runs the System File Checker, it will ask for the Windows CD in order to repair the damage, since Windows also keeps a signed catalogue of the file versions of protected files.
I can't seem to make it clear to you that this is extremely stupid and you will have to find another route to achieve whatever you're trying to achieve - which you still haven't properly explained.
|
|
|
|
|
i know that there's a function called MoveFileEx, which moves or delets a file after reboot! But that won't work for kernel32.dll because movefileex IS part of the kernel32.dll!
If you know another method to change the kernel32.dll then please let me know how!
Thanks in advance!
|
|
|
|
|
|
I must ask that why would you wish to know ?
Like stated, kernel32.dll is a core component of Windows OS series. If it is deleted, moved or altered, it most likely causes the operating system to fail booting. On a non-DOS version of Windows (2000, NT, XP, 2003), this would result in a disastreous effect.
So... Once more, why do you want to delete it ? Are you, per chance, planning on some kind of a doomsday device ? A virus ? I sincerely hope not, because Code Project, as far as I know, was not made for mischievous people.
If you can reason why you'd need to alter it, perhaps we consider in assisting you. Other than that, you should consider another kind of approach to whatever you are trying to accomplish.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Why do you want to delete kernel32? It's a core OS component! Windows won't run without it!! You can't delete it probably because it's loaded into memory and is being used ... for the delete operation!
But if you insist... maybe you can try starting your machine in DOS mode (maybe with a DOS bootable floppy). That way windows won't have loaded it and you can then delete it (after disabling the readonly mode).
"It was when I found out I could make mistakes that I knew I was on to something."
-Ornette Coleman
|
|
|
|