|
The easiest way is to use one of the container classes and one of the string classes, I recommend std::vector and std::string. Then simply copy the strings from the input buffer.
std::vector<std::string> names
char * ptr = buffer;
while (*ptr)
{
names.push_back(ptr);
ptr += strlen(ptr) + 1;
}
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
Here is a way to parse the buffer and load each string into a CStringArray. If you need to.
<code> LPTSTR lpszBuffer = new TCHAR[512+1];
DWORD dwRet = GetPrivateProfileSectionNames( lpszBuffer, 512, lpszFile );
if( dwRet == 0 )
return;
CStringArray secnames;
secnames.RemoveAll();
LPCTSTR p = lpszBuffer;
DWORD dwLen = _tcslen(p);
while( dwLen > 0 )
{
p = &p[dwLen + 1];
secnames.Add(p);
dwLen = _tcslen(p);
}
delete [] lpszBuffer;
for(int i = 0; i < secnames.GetSize(); i++)
{
if( !secnames.GetAt(i).IsEmpty() )
m_cIniEdit.ReplaceSel("["+secnames.GetAt(i)+"]"+"\r\n");
}
</code>
-- modified at 16:31 Saturday 10th June, 2006
|
|
|
|
|
Thanks for all the help so far, but i still can't get it to work. I'm trying to display the section names in a combobox using
SendMessage(hCombo, CB_ADDSTRING, 0, reinterpret_cast<lparam>((LPCTSTR)sectionnames))
I've tinkered with it in the code you guys gave me but I can only get the combobox to display the first section. Also, I'm using win32. Anyone know what I'm doing wrong?
|
|
|
|
|
TCHAR *ptr = sectionnames;
while (*ptr)
{
SendMessage(hCombo, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(ptr));
ptr += _tcslen(ptr) + 1;
}
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
Hi,
I have an array which consist redundant data in it.I want to remove the redundant data and place unqiue data in another array, is there any logic for it.
Thanks in before
James
|
|
|
|
|
|
|
Hi guys!
I have picked up c++ again after a period of rest and I have written a program that is based around random numbers.
Here is what it does: it "calculates" two random numbers (both with a maximum, as you will see in the code. The maximum corresponds with the two arrays of strings stated in the beginning of the main integer) and will output the strings corresponding to those two numbers.
It will, in short, pick a person and pick an activity they can do and put these together to form something like "Mike is eating a sandwich".
In the beginning of the program, the user is asked to input an integer defining the amount of combinations he would like to receive. He might, for instance, type "4" and receive this as output:
Mike is eating a sandwich.
Jack is playing the guitar.
Bella is watching a video.
Dave is playing tennis.
But, and here comes the problem, the program will, in that case, not output those four combinations, but something like this:
Mike is eating a sandwich.
Mike is eating a sandwich.
Mike is eating a sandwich.
Mike is eating a sandwich.
In other words, the program will always use the same random number as it "calculated" for the first combination, thus coming up with the same result for every combination the user wanted.
How can I fix this?
Here's the program, written in c++ and compiled using Borland 5.5:
<br />
WhoDoesWhat.cpp<br />
#include < cstdlib ><br />
#include < ctime ><br />
#include < iostream ><br />
#include < string ><br />
using namespace std;<br />
<br />
int main()<br />
{<br />
<br />
string person[9] = {<br />
"Jason",<br />
"My best friend",<br />
"Uncle Ben",<br />
"Mark",<br />
"Eva",<br />
"Dad",<br />
"My daughter",<br />
"Deborah",<br />
"That kid over there"};<br />
<br />
string activity[9] = {<br />
" is preparing a diner for two.",<br />
" is playing a game of tennis with mum.",<br />
" is making out with his/her girl/boyfriend.",<br />
" is studying his geography exam.",<br />
" is still sleeping.",<br />
" is cruising on his motorcycle.",<br />
" is shooting baskets in the garden.",<br />
" is relaxing by the pool.",<br />
" is coding a simple program in C++"};<br />
<br />
int a = 0;<br />
int b;<br />
int i;<br />
int j;<br />
const int N = 9;<br />
<br />
cout << "Who is doing what? Find out with this program!\n";<br />
<br />
cout << "Of how many persons would you like to know what they are doing?\nThey might be busy doing more things at a time, though!\n"; <br />
<br />
cin >> b;<br />
<br />
cout << endl;<br />
<br />
while (a < b){<br />
srand( (unsigned)time( NULL ) );<br />
<br />
for (i = 0; i < 25; i++) { <br />
rand();}<br />
for (j = 0; j < 25; j++) {<br />
rand();}<br />
<br />
i = (int) N * rand() / (RAND_MAX + a + 3.0);<br />
j = (int) N * rand() / (RAND_MAX + a + 3.0);<br />
<br />
cout << person[i] << activity[j] << endl;<br />
<br />
a++;<br />
}<br />
<br />
cout << "\n\nNow you know a bit more about the people around you!\nCome back later, you hear!";<br />
<br />
getchar();<br />
<br />
return 0;<br />
<br />
}<br />
I hope anyone can help.
Thanks in advance!
Regards,
Peter
-- modified at 12:08 Saturday 10th June, 2006
|
|
|
|
|
You only need to seed the random number generator once.
srand( (unsigned)time( NULL ) );
while (a < b){
i = rand() % N;
j = rand() % N;
cout << person[i] << activity[j] << endl;
a++;
}
|
|
|
|
|
Ah, thanks hfry!
I'll never forget not to put the number generator seeder in a loop.
|
|
|
|
|
I have the probelm for debug my VC++ project with VC 7.1. The error message :
fatal error LNK1000: Internal error during Pass2
Anyone help me?
Thx.
|
|
|
|
|
|
how can i control my microphone volume.i able record my audio using MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE.
sree.
-- modified at 7:12 Saturday 10th June, 2006
|
|
|
|
|
What are the problems we can face with Movewindow?
I used the getclient rect, got the rectangle and then
I am using the move window function.
Then here i got the problems.
The window is not moveing to the particular position.
How to solve that problems.
Any one please let me know.
Nice talking to you.
If you judge people, you have no time to love them. -- Mother Teresa
|
|
|
|
|
Try using GetWindowRect (), ScreenToClient() and then MoveWindow function.
Regards
Amar
|
|
|
|
|
Oh. Thanks a lot. It is working now.
is for you.
Nice talking to you.
If you judge people, you have no time to love them. -- Mother Teresa
|
|
|
|
|
hi,
i am working with microsoft visual c++.But i write a code it will give me
an error and the error is spawning vcspawn.exe and my program will not build
and the tool not build.so help me out for that
Thanks......
nitin
nitin
|
|
|
|
|
Go to project settings and check the paths of header files, and other libraries and files there. Make sure that they are correct.
I hope it helps
We Believe in Excellence
www.aqueelmirza.cjb.net
|
|
|
|
|
hi,
i am working with microsoft visual c++.But i write a code it will give me
an error and the error is spawning vcspawn.exe and my program will not build
and the tool not build.so help me out for that
Thanks......
nitin
nitin
|
|
|
|
|
|
i want to store a image file into "BLOB" value in ORACLE databse.
& i used COleVariant to store the byte array of image file.
but when i try to insert into the oracle db , it through a error "Data type Conversion error"
it's working fine for MSACCESS db using the same COleVariant class..
can u please help me for the same..
it's very urgent ....
send reply
-- modified at 3:03 Saturday 10th June, 2006
|
|
|
|
|
Any help here?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi,
I have created an new application in vc++6, which when run, opens with the ususl CView screen. I want to make a username and password dialog box to apperar befor the CView screen..i.e. if the u/n and p/w is correct, only then the application should open.
Please can you tell me how to do this.
Thanks.
Tara
Fortitudine Vinsinues!
|
|
|
|
|
BOOL SampleApp::InitInstance()
{
CWinApp::InitInstance();
// Display a login dialog box
CLoginDlg dlglogin;
// Check is user press cancel
// Assuming all the validation are handle before returning
if(dlgLogin.DoModal() == IDCANCEL)
return FALSE;
..
.
.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
Regards
Amar
-- modified at 3:25 Saturday 10th June, 2006
|
|
|
|
|
Thanks. I tried it, but I am geting the error ''dlgLogin' : undeclared identifier'
I have created the dialog, included the header file etc. Why is this happening?
Thanks.
Fortitudine Vinsinues!
|
|
|
|