|
Chris Meech wrote: Is each PC on it's own UPS?
Yes, otherwise one PC shutting down would kill the power of any other PC connected to the UPS.
|
|
|
|
|
My ex-colleague and friend ask me for a implementation of itoa. He's preparing for an interview. I don't how it seems to you, but the company here tend to ask questions like that a lot. Well, I'm not prepare for it too, so I ask for google as usual. Although Its a little function, but I'm not gonna let the chance of study slip away!
char* itoa(long n, int base)
{
register char *p;
register int minus;
static char buf[36];
p = &buf[36];
*--p = '\0';
if (n < 0)
{
minus = 1;
n = -n;
}
else
minus = 0;
if (n == 0)
*--p = '0';
else
while (n > 0)
{
*--p = "0123456789abcdef"[n % base];
n /= base;
}
if (minus)
*--p = '-';
return p;
}
After a little study, I figured I know how it was implemented. But there's some thing I'm not sure I right about or why it was implementated the way it is.
First the statement
*--p = "0123456789abcdef"[n % base]; seems strange enough to me at the first glance, but I learned from the book that
"0123456789abcdef" is called "Character array literals", and "...the result of the quoted character array is its starting address in memory....". So add a array element reference operation behind it is same as reference that element at certain index.Is my interpretation right?
Second, why
static char buf[36]; , why not
static char buf[46] or
[56]; ?
|
|
|
|
|
LiYS wrote: static char buf[36];
its static because it is returning the pointer to that array, so it should be not be a local variable allocated on the stack.
Why 36? i feel its a safe enough buffer to store number of digits that the long could have.
-Prakash
|
|
|
|
|
The maximum number of characters to display a long is 34,
so they have a safe side of 2 bytes
since a long is 4 byte the maximum characters that can be use is 34 to
display it in a textual form
4 bytes x 8 bits (base 2) is 32 chars
1 char for the ending '\0'
1 char for the minus
gives 34 chars
BTW: The code isn't error prone
codito ergo sum
|
|
|
|
|
Hi
I am using ExpandEnvironmentStrings() to find the path of pst files of MS Outlook, and passing the string "%USERPROFILE%\\Local Settings\\Application Data\\Microsoft\\Outlook\\*" to ExpandEnvironmentStrings().
Now I want toknow that this path \\Local Settings\\Application Data\\Microsoft\\Outlook\\ is same for all the languages of windows
Please suggest me.
Thanks
|
|
|
|
|
|
Hi,
Can anybody tell me, "Is Reg.dll functions are not supporting Unicode data?". I have got some keys that is in written in Pseudo language. I am able to see the key correctly in windows registry but when i try to read it gives me key with question marks and some un-readable output. What is the reason? Also do let me know in case anybody has solution meanwhile i am searching for some equivalent DLL on net.
Thank you for your time.
Nishith
|
|
|
|
|
i want to make an OCR application & extract text from an image.
i am trying the following approach.
1) i can convert an image to PDF.
2) i can extract text from PDF.
So, theoretically, perhaps OCR is possible this way- to convert image to PDF & then convert the PDF into text & do whatever search operations you have to.
http://www.altimate.ca/flash/ocrdsktp.htmshows the above approach.
However, i can extract text from any normal pdf, it is not happening with a pdf that has been generated from an image.What things may i be missing?
Kindly Guide.
Ankush Mehta
|
|
|
|
|
Simply because your image will be recognized as an image within the pdf file. So you cannot extract text from an image.
From the link you gave us, they probably do character recognition inside their program.
|
|
|
|
|
Hi,
I want to add ATL support to an MFC extension DLL in VC++.
You know that VC++ can add ATL support to regular DLLs but does not add this support to MFC extension DLLs.
Is there any way to add ATL support to MFC extension DLLs.
Should I convert the MFC extension DLL to a regular DLL first?
|
|
|
|
|
I am wondering about what's the best and easiest way to strip trailing whitespace from every single file in a folder, recursively.
I want to write a program/script so that you pass in a folder name and it'll recursively go through all sub-folders and strips trailing whitespace from every single file.
Trailing whitespace includes:
1. whitespaces at end of text lines, strip whitespace but retain text
2. whitespaces on empty lines, strip whitespace but leave the empty line
|
|
|
|
|
kevingpo wrote: I want to write a program/script so that you pass in a folder name and it'll recursively go through all sub-folders and strips trailing whitespace from every single file.
Open the file. Set the file pointer to the end using SetFilePointer() . Read the character. If it is non-white, call SetEndOfFile() and close the file. Otherwise, read the previous character...
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
|
|
|
|
|
See following code:
main (....)
{
CString strPath = "*.*";
Trim (strPath);
}
void Trim (CString &strPath)
{
CFileFind Info;
CStdioFile File;
CString strRecord;
BOOL bLoop;
bLoop = Info.FindFile ((LPCTSTR)strPath, 0);
while (bLoop)
{
bLoop = Info.FindNextFile ();
if ( Info.IsDirectory ()
&& !Info.IsDots ())
{
CString strSub;
strSub = Info.GetFilePath ();
strSub += "\\*.*";
Strip (strSub);
}
else if ( !Info.IsDirectory ()
&& !Info.IsHidden ()
&& !Info.IsReadOnly ())
{
printf ("%s\n",(LPCTSTR)Info.GetFilePath ());
if (File.Open ((LPCTSTR)Info.GetFilePath (), CFile::modeReadWrite|CFile::typeBinary, NULL))
{
DWORD dwReadPosition = 0;
DWORD dwWritePosition = 0;
UINT nRecord = 0;
try
{
while (File.ReadString (strRecord))
{
dwReadPosition = File.GetPosition ();
strRecord.TrimRight ();
File.Seek (dwWritePosition, CFile::begin);
File.WriteString ((LPCTSTR)strRecord);
File.WriteString ("\r\n");
dwWritePosition = File.GetPosition ();
File.Seek (dwReadPosition, CFile::begin);
printf ("%d\r",++nRecord);
}
printf ("\n");
}
catch (CFileException *Exception)
{
Exception->Delete ();
fprintf (stderr,"\nError writing to file\n");
File.Close ();
exit (1);
}
File.SetLength (dwWritePosition);
File.Close ();
}
}
}
}
This code example expects you use MFC. If you don't, you will have to use the standard FILE * type of routines.
Good luck.
William
|
|
|
|
|
Can someone tell me how a '+' operation is internally handled by the compiler(if possible with an example). Meaning that if I say 5+10 wat happens internally and how the compiler handles it??
|
|
|
|
|
From what I understand, all a compiler does (MSVC for example) is to convert your source code into machine readable code called ASM. If you google around you can find many examples of this language, which in turn will give you a better idea of what is actually happening behind the scenes.
|
|
|
|
|
waldermort wrote: ...all a compiler does (MSVC for example) is to convert your source code into machine readable code called ASM.
Not quite. Assembly is just another language, although not as high-level as C. What the compiler and linker do is create machine code that matches the instruction set of the processor.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
|
|
|
|
|
On a very low level, you change the current in some transistors so that the resulting transistor combination of open and closed transistors is interpreted as 15 by your computer.
~RaGE();
|
|
|
|
|
this is how VC8.0 handles this:
int a, b, c;
a = 5;
<code>00416C23 mov dword ptr [a],5 </code>
b = 10;
<code>00416C2A mov dword ptr [b],0Ah </code>
c = a + b;
<code>00416C31 mov eax,dword ptr [a]
00416C34 add eax,dword ptr [b]
00416C37 mov dword ptr [c],eax</code>
codito ergo sum
|
|
|
|
|
|
his question was refering to the + sign,
-Prakash
|
|
|
|
|
Regarding these resource files I know it is possible to store just about any type of binary data, but the problem is access. I am trying to include an Excel .xls file into my project. Including this as a plain file is no problem, but when added as a resource I have trouble accessing it. Namely with functions that expect a string pointer.
This xls file is the master template for which my program would copy/fill-in/manipulate. Therefore I would prefer it to be hardcoded into the exe where it would be pretty much impossible to be deleted or edited.
Is there a workaround or a method of conversion?
|
|
|
|
|
If I'm interpreting your situation correctly, you're saying you have an 'integer' identifier (defined in resource.h) for your Excel resource and need to know how to form the 'string' value that can be used to reference it.
To convert that integer value to a 'string' (wink, wink) Microsoft provides the MAKEINTRESOURCE[^] macro.
Is this what you are looking for?
Regards,
Dan
Remember kids, we're trained professionals. Don't try this at home!
|
|
|
|
|
Exactly what I was looking for. Thankyou
|
|
|
|
|
Is this article of any help?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
|
|
|
|
|
Thanks, you answered what would have been my next question :p
|
|
|
|