|
I actually start try out declaring the structure but i got stuck in the mids of doing.
struct record
{
char name[10],personID[10],password[10]
};
this is how i declared.. but the problem is assume the size of password is fix so that ok, i can declared a static one.. but for the pass word and the name.. that can be a problem
etc .txt
peter 1111 abc124
michard 1342 stbjllll
michelle 2312 vjhbvk
so im stucked... i just wanna be able to retieve the id and password from the .txt file then compare it with the user input to check if it correct..
|
|
|
|
|
Looks like ‘Iain Clarke’ gave a reasonable answer to your problem.
As for using structure/record type of format, you would have to place some restrictions on the field sizes, as you have discovered. But since you are dealing with a ‘.txt’ file, attempting to read it using a structure would be a bad idea, as it does not meet the requirement of structured data. Unstructured text data, in the form you presented, should probably be read one line at a time (kind of slow), parsed, and stored internally in any form you wish, including an array of records/structures.
The following is just for my entertainment, but it may give you some ideas:
enum my_field_sizes { REC_NSIZE=32, REC_IDSIZE=10, REC_PWSIZE=12};
typedef struct my_record
{
char name[REC_NSIZE], id[REC_IDSIZE], pw[REC_PWSIZE];
} MY_RECORD;
const char* My_ReadField(const char* pStr, char* pOut, unsigned nOutSize)
{
if( pStr && *pStr && pOut && nOutSize )
{
int i;
while( isspace(*pStr) )
++pStr;
for( i=0; i < nOutSize && !isspace(*pStr) && *pStr; ++i, ++pStr )
pOut[i] = *pStr;
i = (i < nOutSize) ? i : (nOutSize-1);
pOut[i] = ‘\0’;
while( !isspace(*pStr) && *pStr )
++pStr;
}
return(pStr);
}
void My_ReadRecordLine(MY_RECORD* pRec, const char* pLine)
{
const char* pNextField = pLine;
memset(pRec, 0, sizeof(MY_RECORD));
pNextField = My_ReadField(pNextField, pRec->name, REC_NSIZE);
pNextField = My_ReadField(pNextField, pRec->id, REC_IDSIZE);
My_ReadField(pNextField, pRec->pw, REC_PWSIZE);
}
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
You may only be interested in strings #2 & #3 - but you'll need to read #1 as well. Just throw it away very rapidly!
You need to break the program in to bits.
1/ Open the text file.
2/ Go through it one line at a time
3/ parse the line to get the three thingies from it (sscanf)
4/ throw away Name, and hang on to the other two.
5/ go back to step 2, until you get to EOF (or some other method)
Here is step 3.
Assuming you have a character string with the three words / numbers in it.
char test [] = "iain 1234 clarke";
char password [256];
int id;
while (GetThingsFromLine (test, &id, password))
{
DoStuff (id, password);
}
BOOL GetThingsFromLine (char *test, int *id, char *password)
{
char name [256];
return sscanf (test, "%s %i %s", name, id, password) != 0;
}
I hope that helps a bit!
Iain.
|
|
|
|
|
return sscanf (test, "%s %i %s", name, id, password) != 0;
You haven't got the standard library memorized? sscanf() returns the number of matches (hopefully 3 in this case) or EOF, not true or false. So although this is the right idea it should probably be an == 3.
(and the %i should be a %d)
David's strtok() suggestion is the way to go in my opinion as it gives you the opportunity to validate the data.
|
|
|
|
|
Hi,
Using a structure will be good. Thts what i feel.
|
|
|
|
|
If there is a unique identifier on each side of the ID, you can read each line of the file, and split it into its (three) parts using strtok() . Although not recommended, you can also use fscanf() to parse each line.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
You know,the API function GetVolumeInformation()would get a serial number of a device.
But the number is variable,and is not be writen by the productor,so it can be writen again and again.
I want to encrypt some files using the devices firmware serial number.
Some one would like to tell me how to get such information?
Thanks.
GOOD LUCK.
|
|
|
|
|
look at the documentation of the design specifications,
if there is no api, the firmware development team should encode
a firmware function program to pass the handle higher layer
|
|
|
|
|
I'm an ugly guy, have't used CImageList before.
I've viewed some code use CImageList like this.
First declare class members:
CImageList m_imlListCtrl;
CListCtrl m_list;
then
BOOL CMyDlg::OnInitDialog()
{
CImageList imlStack;
imlStack.Create(code);
imlStack.Add(theApp.LoadIcon(IDI_A));
imlStack.Add(theApp.LoadIcon(IDI_B));
m_list.SetImageList(&imlStack);
m_imlListCtrl.DeleteImageList();
m_imlListCtrl.Attach(imlStack.Detach());
}
why not
m_imlListCtrl.DeleteImageList();
m_imlListCtrl.Attach(imlStack.Detach());
m_list.SetImageList(&m_imlListCtrl);
DO TELL ME. or give me some article guides.
|
|
|
|
|
Why not like this.
m_imlListCtrl.DeleteImageList(); <br />
m_imlListCtrl.Create(code); <br />
m_imlListCtrl.Add(theApp.LoadIcon(IDI_A)); <br />
m_imlListCtrl.Add(theApp.LoadIcon(IDI_B));<br />
m_list.SetImageList(&m_imlListCtrl);
The second method you proposed is also ok. but why are you creating a local CImageList object CImageList imlStack; ?
|
|
|
|
|
Except icon you can add your bitmap.
CBitmap bmp;
bmp.LoadBitmap(IDB_MYBITMAP);
pmyImageList->Add(&bmp, RGB(0, 0, 0));
|
|
|
|
|
TO Naveen.R
I'm not familar to CImageList at all.
The code I posted is the source code in EMULE. I'm curious too why use the stack imagelist to set the imagelist of the CListCtrl, while not like your codes.
TO Hamid.
Can load 2 bitmaps like this:
<br />
CBitmap bmp;<br />
bmp.LoadBitmap(IDB_MYBITMAP);<br />
m_iml.Add(&bmp, RGB(0, 0, 0));<br />
<br />
bmp.LoadBitmap(IDB_MYBITMAP2);<br />
m_iml.Add(&bmp, RGB(0, 0, 0));<br />
|
|
|
|
|
But why two bitmaps you can use more files anyway I think my answer was incorrect you use of Bold for font.;P
|
|
|
|
|
|
purplee85 wrote: how i could get gdiplus.h header file?
Download the latest platform SDK.
|
|
|
|
|
|
purplee85 wrote: Subject:Re: [Message Deleted]
Sender:purplee85
Please never delete your message.. it could be helpful for other!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Now I have a question of you why you delete your message?
|
|
|
|
|
Hi All,
I am using VC++ win32 application in VS 2005.I have created one project as win32 and now I want to add one another project which is omnithread into same solution.I want to make it as static library.
How can I use omnithread.h,nt.h and nt.cpp files in this project.And what my project settings I have to change?Please suggest me.I tried this by reading the Readme.Win32 but I did not get success.
Can anyone test the application making new project with including other project as omnithread and use this project's classes into the ohter project in the same solution. You can download these files from the below link.
http://www.koders.com/cpp/fidB630376C86E504519D0CBF450C0AA4358CFC3915.aspx?s=omnithread.h[^]
If you get any idea or any suggetion then reply me.
Thanks in Advace.
Ashish Bhatt
|
|
|
|
|
Hmmm, where to start.
Simple answer:
#include "omnithread.h"
And add nt.cpp to your project.
Longer answer:
If you're struggling to include a header, then threads may be overly ambitious.
Bit Longer answer:
Is there a reason you're not asking on www.koders.com where the files are from? I know that *I'm* not going to make a dummy project, download those files, work out what they're about, test it, then tell you. That's the sort of thing you PAY people for.
Iain.
|
|
|
|
|
hai,
in which forum did you actually want to post this.
|
|
|
|
|
|
hai all.
that was her question.
|
|
|
|
|
So her question was a general question.;)
|
|
|
|
|
Hi all,
Anybody know, please, how i can concatenate CString with hex values?
<br />
CString message = _T("Hello");<br />
unsigned char HexPrepend[] = { 0x01, 0x02, 0x03, 0x4 };<br />
So in memory result should be:
<br />
0102030448656C6C6F<br />
Regards,
L.
|
|
|
|
|