|
See if this helps.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello everyone!
I'm trying to enumerate all the paths on my C:\ drive. I want this:
C:
C:\folder
C:\folder\subfolder
C:\folder\subfolder\subsubfolder
C:\folder\subfolder\subsubfolder\etc
...but instead I get this:
C:
C:\folder
C:\folder\.
C:\folder\.\.
C:\folder\.\.\.
What's the correct way of doing this? I'm using FindFirstFile and FindNextFile, not using MFC.
Thanks people!
Windows Calculator told me I will die at 28.
|
|
|
|
|
See this illustration from MSDN, the part you are missing in colored in red...
#include <afx.h>
#include <iostream>
using namespace std;
void Recurse(LPCTSTR pstr)
{
CFileFind finder;
CString strWildcard(pstr);
strWildcard += _T("\\*.*");
BOOL bWorking = finder.FindFile(strWildcard);
while (bWorking)
{
bWorking = finder.FindNextFile();
<code>
<code> if (finder.IsDots())
continue;</code>
if (finder.IsDirectory())
{
CString str = finder.GetFilePath();
cout << (LPCTSTR) str << endl;
Recurse(str);
}
}
finder.Close();
}
void main()
{
if (!AfxWinInit(GetModuleHandle(NULL), NULL, GetCommandLine(), 0)
cout << "panic!" << endl;
else
Recurse(_T("C:"));
} A dot(.) indicates current directory and a dot dot(..) indicates parent directory. So you need to ignore these two entries.
|
|
|
|
|
Is there any way to do this without MFC and C++ (just plain C & Win32)?
Thanks!
Windows Calculator told me I will die at 28.
|
|
|
|
|
Lord Kixdemp wrote: Is there any way to do this without MFC and C++ (just plain C & Win32)?
Yeah, the source code of CFileFind::IsDots is as follows, now maybe you know how to do it...
BOOL CFileFind::IsDots() const
{
ASSERT(m_hContext != NULL);
ASSERT_VALID(this);
BOOL bResult = FALSE;
if (m_pFoundInfo != NULL && IsDirectory())
{
LPWIN32_FIND_DATA pFindData = (LPWIN32_FIND_DATA) m_pFoundInfo;
if (pFindData->cFileName[0] == '.')
{
if (pFindData->cFileName[1] == '\0' ||
(pFindData->cFileName[1] == '.' &&
pFindData->cFileName[2] == '\0'))
{
bResult = TRUE;
}
}
}
return bResult;
}
|
|
|
|
|
When you're enumerating, skip any dirs named "." and ".."
|
|
|
|
|
Does MS Chart control supports unicode characters?
I want to set Legends for MSChart control in different languages.
But when I am trying any language other than english,the MSChart control showing garbage values insted of provided string......
|
|
|
|
|
Hi,
Im trying to make a word game. But im kinda stuck with how to hussle the letters.
This is the code i got so far:
char letters[] = {'a', 'v', 'e', 'd', 'k', 'u', 'r', 'n', 'e'};
for(char * c = letters; c < &letters[sizeof(letters)]; c++)
{
}
Im trying to search all possible letter combinations starting with a word containing 2 letters and max 9.
After that, i'll compare the words it found with the dictionary so that the user knows if the word exist or not.
But comparing wont be a problem. The problem right now is to search all possible word combinations.
Anyone got some kind of an algorithm for this?
Thanks in advance!
|
|
|
|
|
You can use recursion, for instance.
You could also have a look at STLs and some algorithms for handling strings, combination, permutations,...
As a side note,
Yustme wrote: c < &letters[sizeof(letters)]
this is freaking code.
|
|
|
|
|
Hi,
I found this: c < &letters[sizeof(letters)] , on the net, was looking what it would give me, since array's dont have .size() method.
|
|
|
|
|
Here a better way, IMHO, to retrieve the size of an array:
char array[] = {1,2,3};
int size = sizeof(array)/sizeof(array[0]);
|
|
|
|
|
Hi,
I fixed that a few hours ago, thank you
|
|
|
|
|
This takes me back. I have uploaded jumble.zip, which is a word game much like you describe. The code is hideous, and only covers words of 4 - 7 chars in length. The basic idea of the game is to unscramble letters to find the word. For example, if you entered
jumble eraop it would output "opera". I'm sure you could improve the code 1000%, but it's fast because the dictionary is split into files of specific word lengths. If you had a decent dictionary, it would be trivial to do the same, for words of 2 - 9. Let me know how it turns out.
|
|
|
|
|
Hi,
I got a dictionary in a plain text format.
Thank you for the sample you gave me.
I'll let you know how it'll turn out
|
|
|
|
|
Hi,
I found an algorithm which was used for an int array.
I modified it so i can use it for my char array.
It works good but not as how i wanted it to work.
This is how it looks like right now:
<br />
void permute(char *v, const int start, const int n);<br />
void print(const char *v, const int size);<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
char v[] = {'a', 'v', 'e', 'd', 'k', 'u', 'r', 'n', 'e'};<br />
permute(v, 0, sizeof(v)/sizeof(char));<br />
<br />
system("pause");<br />
return 0;<br />
}<br />
<br />
void print(const char *v, const int size)<br />
{<br />
if (v != 0) <br />
{<br />
for (int i = 0; i < size; i++) <br />
{<br />
cout << v[i];<br />
}<br />
cout << endl;<br />
}<br />
}
<br />
<br />
void permute(char *v, const int start, const int n)<br />
{ <br />
if (start == n-1)<br />
print(v, n);<br />
<br />
else <br />
{<br />
for (int i = start; i < n; i++) <br />
{<br />
char tmp = v[i];<br />
<br />
v[i] = v[start];<br />
v[start] = tmp;<br />
permute(v, start+1, n);<br />
v[start] = v[i];<br />
v[i] = tmp;<br />
}<br />
}<br />
}<br />
It's making letter combinations with only all letters.
It should actually start with 2 letters and then continue until all 9 letter combinations are found.
|
|
|
|
|
Why don't you do something clever like computing the hash of your letter combinations / words, but do it in a way that is independent of letter order. The hash value of the jumbled combination would match the hash value of the unjumbled word. Then you would only have to search the (hopefully) few words with matching hash values.
One way you could do this would be to use a standard hash routine, but sort the letters in the word into alphabetical order prior to hashing them.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
How could I get the Instance Handle from another Process ID?
Maybe the Process has no any windows, so I can't use the GetWindowLong API.
And I know nothing about the Module Name of the third Process, so I can't use the GetModuleHandle API,too.
So,how could I get the Instance Handle from another Process ID?Or how could I get the Module Name of the third Process,that I can use the GetModuleHandle API for it?
|
|
|
|
|
Billypon wrote: How could I get the Instance Handle from another Process ID?
Use OpenProcess API.
HANDLE hProcHandle = ::OpenProcess( PROCESS_ALL_ACCESS, FALSE, dwAnotherProcessID );
ASSERT( hProcHandle );
The first parameter specifies type of access needed. PROCESS_ALL_ACCESS won't always work.
The type of action that you want to take on the remote process will determine the access needed. For eg: to terminate a process you will need PROCESS_TERMINATE access right or for ReadProcessMemory and WriteProcessMemory PROCESS_VM_**** rights.
It's safe to have the SeDebugPrivilege enabled for your application if would like to do some advanced stuff with the other process.
You might be interested to look up this article -> http://www.codeproject.com/useritems/processviewer.asp[^]
|
|
|
|
|
Hello All
What are the good books / internet links available for learning STL ? Can anybody suggest.
Thanx.
|
|
|
|
|
Try C++ The Complete reference - By Herbert Schild
STL you will find many samples in MSDN also..
you can check online MSDN.
|
|
|
|
|
A reference book you absolutely want is
Nicolai M. Josuttis, "The C++ Standard Library - A Tutorial and Reference", Addison-Wesley
As a Link, I recommend the SGI pages[^]
Failure is not an option - it's built right in.
|
|
|
|
|
My favorite is Christian Graus[^] Check in the STL part of the link for his article on STLs.
|
|
|
|
|
Hi everybody,
i realized already a drag&drop of text from out a CListCtrl into a MS Word Document.
I used COleDropSource, COleDataSource, CSharedFile and CArchive
How does it work with bitmap?
Copy a bitmap into the clipboard via OpenClipboard & SetClipboardData works fine.
But it stores only the bitmap into the clipboard. No Drag&Drop possibility.
So i need to work with COleDropSource and COleDataSource, right?
Does is work via .WriteObject or WriteClass ?
Big thanks for help
|
|
|
|
|
Why does the below code throw exception in parent class?
#include <iostream><br />
<br />
using namespace std;<br />
<br />
class A<br />
{<br />
};<br />
<br />
class B : public A<br />
{<br />
};<br />
<br />
int main()<br />
{<br />
B b;<br />
<br />
try<br />
{<br />
throw b;<br />
}<br />
catch (A& ea)<br />
{<br />
cout << "Caught an instance of A" << endl;<br />
}<br />
catch (B& eb)<br />
{<br />
cout << "Caught an instance of B" << endl;<br />
}<br />
return 0;<br />
}
|
|
|
|
|
if you are using VC++ IDE (dont know about other ide's )you will get some warning when you compile.
that warning will make it clear why it is gettign thrown in parent class.
Try changing the sequence of catch block you will undestand the reason yourself.
|
|
|
|