| | |
please help me recognize this piece of code!
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2009
Posts: 15
Reputation:
Solved Threads: 0
Hello everyone,
I'm into writting a project ,that's all about dealing with directories and more specificly to code something that finally well work as"windows command prompt" in standard console....
i Got alot help from the experts here & got alot progressed, But a bug has occured in between:
yestreday i got announced that we've got to use the WIN32_FIND_DATA stuct and use it's members to deal with directories only. To be given more help the teacher wrote down this code for us :
this function supossedly is to identify whether the variable "temp" is a directory in the system or not !
But the fact is that i cant realize what process is going on. all my searches about this stuct looks quite wierd i cant make head or tails of. ccan any one pppplllleeeaassse clarify for me what do the items above, each one of them, do ? .....as well as letting me know how i can pass an argument to this function ?, is the argument "wchar_t" the address we're gonna check its validity ...or what is it at all ? arent all addresses in char* mode ?... how to modify them if yes ??? ....i feel totally mixed up with these few lines ! any helps will highly be appriciated !
Thanx in advance
Mahsa M
19
student of computer engeneering **in the very begining of course**
I'm into writting a project ,that's all about dealing with directories and more specificly to code something that finally well work as"windows command prompt" in standard console....
i Got alot help from the experts here & got alot progressed, But a bug has occured in between:
yestreday i got announced that we've got to use the WIN32_FIND_DATA stuct and use it's members to deal with directories only. To be given more help the teacher wrote down this code for us :
C++ Syntax (Toggle Plain Text)
bool isdirecory(wchar_t *temp) { WIN32_FIND_DATA filedata; HANDLE h.search; h.search=FindFirstFile(temp, & filedata); if (filedata.dwattributes==16) return true; else return false; }
But the fact is that i cant realize what process is going on. all my searches about this stuct looks quite wierd i cant make head or tails of. ccan any one pppplllleeeaassse clarify for me what do the items above, each one of them, do ? .....as well as letting me know how i can pass an argument to this function ?, is the argument "wchar_t" the address we're gonna check its validity ...or what is it at all ? arent all addresses in char* mode ?... how to modify them if yes ??? ....i feel totally mixed up with these few lines ! any helps will highly be appriciated !
Thanx in advance
Mahsa M
19
student of computer engeneering **in the very begining of course**
The only weird thing is h.search isn't a valid variable name.
As for the rest, have you read these?
http://msdn.microsoft.com/en-us/library/aa365740.aspx
Do you see where 16 comes from?
http://msdn.microsoft.com/en-us/libr...18(VS.85).aspx
As for the rest, have you read these?
http://msdn.microsoft.com/en-us/library/aa365740.aspx
Do you see where 16 comes from?
http://msdn.microsoft.com/en-us/libr...18(VS.85).aspx
•
•
Join Date: Jan 2009
Posts: 15
Reputation:
Solved Threads: 0
Thank u very much,
yeah, i alreday had taken a look at those MSDN pages, i know that 16 means the given address is a true directory.
but what still remains unsolved is that i don know how to pass an argument to this function.
for example if i'm supposed to detemin if "C:\program files\Firefox" is one of the existing directories of my computer, how can i use this function? .. i cant change it into wchar_t* !..my searches reveal confusing results !
would u write me a comprehensive example , with datas given, so that i betterly undersatnd? thank u very much.
yeah, i alreday had taken a look at those MSDN pages, i know that 16 means the given address is a true directory.
but what still remains unsolved is that i don know how to pass an argument to this function.
for example if i'm supposed to detemin if "C:\program files\Firefox" is one of the existing directories of my computer, how can i use this function? .. i cant change it into wchar_t* !..my searches reveal confusing results !
would u write me a comprehensive example , with datas given, so that i betterly undersatnd? thank u very much.
•
•
Join Date: Jan 2009
Posts: 15
Reputation:
Solved Threads: 0
Thank u big time !
it now seems like i can be hopeful to get a nerve relief about performing my project.
So, Does the Function TEXT(qoate ) change a char* to wchar_t ??
it seems like it does so, but it does it abit more complicated than i thought at first...what does the term "qoate" exactly mean here ??
..when i use the code below:
[code]
char* str="C:\WINDOWS";
wchar_t* longstr=TEXT(str);
[\code]
im given the following error:
error C2065: 'Lstr' : undeclared identifier
so...how can i change it in a way that i be able to pass a string to the TEXT argument ?
..i need it since the user is to enter the directory address, and i am to determin wether he's entered wrong or write ?
Tanx alot
Mahsa
it now seems like i can be hopeful to get a nerve relief about performing my project.
So, Does the Function TEXT(qoate ) change a char* to wchar_t ??
it seems like it does so, but it does it abit more complicated than i thought at first...what does the term "qoate" exactly mean here ??
..when i use the code below:
[code]
char* str="C:\WINDOWS";
wchar_t* longstr=TEXT(str);
[\code]
im given the following error:
error C2065: 'Lstr' : undeclared identifier
so...how can i change it in a way that i be able to pass a string to the TEXT argument ?
..i need it since the user is to enter the directory address, and i am to determin wether he's entered wrong or write ?
Tanx alot
Mahsa
TEXT isn't a function, it's a macro.
So it's limited to "strings"
It's not a good idea to try to keep both forms in your program, except for when you absolutely have to choose one specific form for a particular case. Even then, try to minimise the scope so it doesn't pollute the rest of your code.
For example, you might do
Where you might have previously used strcpy to copy a string, you would use _tcscpy() instead, which does the right thing depending on whether you compile for ANSI or UNICODE.
This is a handy list-on-a-page of all the mapped API calls.
http://www.i18nguy.com/unicode/c-unicode.html
However, this being C++ (I assume, since this is the forum you posted on), you should start to look at the wide character equivalent of std::string to do most of the work for you.
Lets see how long it takes your teacher to enter the real world of C++.
So it's limited to "strings"
It's not a good idea to try to keep both forms in your program, except for when you absolutely have to choose one specific form for a particular case. Even then, try to minimise the scope so it doesn't pollute the rest of your code.
For example, you might do
TCHAR *str = TEXT("C:\\Windows");
TCHAR *s2 = str;Where you might have previously used strcpy to copy a string, you would use _tcscpy() instead, which does the right thing depending on whether you compile for ANSI or UNICODE.
This is a handy list-on-a-page of all the mapped API calls.
http://www.i18nguy.com/unicode/c-unicode.html
However, this being C++ (I assume, since this is the forum you posted on), you should start to look at the wide character equivalent of std::string to do most of the work for you.
Lets see how long it takes your teacher to enter the real world of C++.
•
•
Join Date: Jan 2009
Posts: 15
Reputation:
Solved Threads: 0
Thank u Salem alot !!
yes, you're right, that would be bothering to try to use the both forms of wchar_t* and char*, so instead i'll try to deal with merely unicode charactors.
The link you put for me is surprisingly filtered
.. i'll then try connections through different ways to see whether i can open it or not ?.. would u do me a favor and copy them for me on the page here ?...i'll highly appriciate it.
one more critical question:
Does WIN32_find_data structure provide me with something that i need to use to get a list of files & folders in a directory ? like what <Dir> does in windows... i viwed the data memebres of the struct, i couldnt find one...
If this struct is of no help, what recomandations do u have ??
ps-Yeah, u're right...Perhaps there's still long way till we learn wholy about c++, but the point was that i didnt know to which world ( c or c++) my question exactly refers! ( even worse!)
i'm almost lost between my scattered knowledge of both worlds !
Thank uuuuu greatly.
Mahsa
yes, you're right, that would be bothering to try to use the both forms of wchar_t* and char*, so instead i'll try to deal with merely unicode charactors.
The link you put for me is surprisingly filtered
.. i'll then try connections through different ways to see whether i can open it or not ?.. would u do me a favor and copy them for me on the page here ?...i'll highly appriciate it. one more critical question:
Does WIN32_find_data structure provide me with something that i need to use to get a list of files & folders in a directory ? like what <Dir> does in windows... i viwed the data memebres of the struct, i couldnt find one...
If this struct is of no help, what recomandations do u have ??
ps-Yeah, u're right...Perhaps there's still long way till we learn wholy about c++, but the point was that i didnt know to which world ( c or c++) my question exactly refers! ( even worse!)
i'm almost lost between my scattered knowledge of both worlds !Thank uuuuu greatly.
Mahsa
![]() |
Similar Threads
- There is an elephant on the loo! (Geeks' Lounge)
- Tutorial: Forms: styling text fields with CSS and HTML (Site Layout and Usability)
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- StringUtil (Java)
- What input reading functions are there in C? (C)
- Creating a Command Line Parser (C++)
- Adding decimal numbers together? (C)
Other Threads in the C++ Forum
- Previous Thread: c/c++ decompiler
- Next Thread: when is the destructor fire?
Views: 512 | Replies: 8
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






