|
Cant figure out how to just remove LBS_SORT and nothing else. Dang!
|
|
|
|
|
|
In Visual C++, i need to write a function which takes in an array of Strings as parameter, and this array of strings will be returned to the caller. How could i do it?
possible definitions i considered:
1) void Func(char *target[SIZE1][SIZE2]){//definition}
2) char [SIZE1][SIZE2] Func(void) {//definition}
3) void Func(char **target[SIZE1]) {//definition}
4) char *[SIZE1] Func(void) {//definition}
Are all the above definitions correct? Could you give example of definitions and relevant calling? I need to use character pointers to represent string and do other string operation.
Thanks in advance
Regards
World on the way
|
|
|
|
|
In reality, when talking about function parameters, these are the same:
<br />
void Func1(char *target[size]);<br />
void Func2(char *target[]);<br />
void Func3(char **target);<br />
A string is a pointer to a character. So an array of strings would be a pointer to strings, or a pointer to a pointer to a character. Here's a quickie example. Note that when passing in array pointers to functions, you need to pass in the size of that array. (Yet another reason to use classes..)
void Func(char **strings, int size)
{
for(int i = 0; i < size; i++)
{
cout << "String " << i << " is: " << strings[i] << endl;
}
}
You might allocate such an array like this:
int size = 10;
char **stringArray = new char * [size];
for(int i = 0; i < size; i++)
{
stringArray[i] = strdup("Chimpanzee");
}
Since I just hacked this out right now, without a compiler, fixing any bugs is left as an exercise to the reader.
If your nose runs and your feet smell, then you're built upside down.
|
|
|
|
|
Thanks for your fast response.
In fact I concern more about how to return an array of string. What I need to do is write a function which will take a long string and analyze this string, then return the array of substrings.
Another function is to take a bit stream as input parameter and return the substrings. I have tried my code, but it always cause compiling errors which frustrated me.
My code is as following.
void Func(char *longSourceString, char *subString[numOfSubStrings][subStringSize]) { }<br />
<br />
char targetBuffer[numOfSubStrings][subStringSize];<br />
Func(longSourceString, &targetBuffer);
As you see, i want get back the array of substrings. By the way, there is no way to use strtok() function here. And do i have any possible ways to use reference variable here? Is is valid to use a reference variable which refer to a pointer, a character pointer, an array?
Thanks in advance.
Regards
World on the way
|
|
|
|
|
void Func(CStringArray &arrayStr)
{
}
|
|
|
|
|
pass in a std::vector of std::strings. Pass it by reference. Don't use MFC container classes unless absolutely forced to, they are gay.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Hi,
I have a custom toolbar created by my CMainFrame class. In the OnCreate handler for CMainFrame I add a CComboBox and a CEdit control. Both display hideously large text.
I've tried using SetFont() on both controls to change this but it only seems to affect the clipping area for the text within each control - the actual text is still drawn really big but this time cut-off. Surely I don't have to implement a User-draw just to change the font size do I?
Can anyone help please?
Many thanks,
S
|
|
|
|
|
Hi,
i encounter a similar problem in a combobox embedded edit control. if you managed to overcome this without drawing text through device context, your solution would be highly appreciated.
Thank you!
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Email: y_becker@netvision.net.il
|
|
|
|
|
Given these requirements for a console application:
Enter a series of integers seperated by whitespace. The first integer represents the quantity of integers to follow.
Ex. 3 5 18 21
or. 5 17 -46 3 198 2
I have been attempting the following to read the integers and store them in a vector:
scanf("%d", &cnt);
for(int i = 1; i <= cnt + 1; i++)
{
scanf("%d", &n);
aInts.push_back(n);
}
This works fine, unless someone enters fewer integers than the initial integer indicates. (ex. 3 19 5)
How can I test to see if the end of the input stream has been reached?
I have attempted the same type of logic using cin, to no avail.
Thank you in advance for your help.
|
|
|
|
|
First of all, scanf ? Are you required by your class to use C instead of C++ for streaming ? If so, why ? You're using STL anyhow.
Secondly:
for(int i = 1; i <= cnt + 1; i++)
why not
i < cnt ???
If you use cin, you can check the stream state to see if there is anything else there. The whole first integer represents the quantity idea is flawed IMO, you should just accept the line, and read the stream while it is good.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Apparently some of my last advice was a little off. I've not done any C++ for a while now. The following is a complete solution that reads a line, then it extracts the numbers from the string, it assumes that only numbers are entered ( which is bad ), but it will only read the number of items you entered as the first digit, but if there is less, it just breaks and does not blow up. You could make it present an error if you'd like.
This is obviously your homework, and I ask you not to use this code unless you first do the research to be able to reproduce it yourself, and understand/explain what it does and how it does it.
<br />
<br />
#include <iostream><br />
#include <vector><br />
#include <string><br />
#include <algorithm><br />
<br />
using std::cin;<br />
using std::cout;<br />
using std::vector;<br />
using std::string;<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
string s;<br />
int nCount;<br />
int n;<br />
<br />
std::getline(cin, s);<br />
<br />
int nPos = s.find(' ', 0);<br />
<br />
nCount = ::atoi(s.substr(0, nPos).c_str());<br />
<br />
vector<int> vecInt;<br />
<br />
int nStart = nPos + 1;<br />
<br />
for (int i = 0; i < nCount; ++i)<br />
{<br />
nPos = s.find(' ', nStart);<br />
<br />
if (nPos > 0)<br />
{<br />
vecInt.push_back(::atoi(s.substr(nStart, nPos).c_str()));<br />
nStart = nPos + 1;<br />
}<br />
else<br />
{<br />
vecInt.push_back(::atoi(s.substr(nStart, s.size()).c_str()));<br />
break;<br />
}<br />
}<br />
<br />
std::vector<int>::iterator first = vecInt.begin();<br />
std::vector<int>::iterator end = vecInt.end();<br />
<br />
bool bFirst = true;<br />
<br />
for(;first != end; ++first)<br />
{<br />
if (!bFirst) cout << ", ";<br />
cout << *first;<br />
bFirst = false;<br />
}<br />
<br />
cin >> s;<br />
<br />
return 0;<br />
}<br />
<br />
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Thanks for your reply.
This is actually not a school assignment, though it is very similar to the assignments I was given in C and C++ class. This is a "test" I was given at work. I was able to make it work nicely by reading everything as one long string and parsing it myself but, for reasons that escape me, I was asked to re-do it. The "boss" said I can use any references I like to get this accomplished.
I attempted scanf out of desperation! I could not get cin to work like I wanted it to work.
Thanks for your help.
roger
|
|
|
|
|
Has anybody here worked on LSP? I'm looking in developing an LSP to redirect the TCP calls to a file? Has anybody tried it? any suggestions/sample code? I've already have gone through the sample comes with the Platform SDK feb 2003.
Thanx
mustcat
|
|
|
|
|
almost a homework question!
Don't try it, just do it!
|
|
|
|
|
what exactly do you mean? it's too simple just go ahead and do it maybe for you cuz I'm even stuck on debuging the sample code right now
here is the error you maybe able to help me... I've already downloaded the symbols and also checked the "Load COAF & Export" under Tools-->Options-->Debug tab
Loaded 'C:\WINNT\system32\msvcrt.dll', no matching symbolic information found.
Loaded 'C:\WINNT\system32\rpcrt4.dll', no matching symbolic information found.
Loaded 'C:\WINNT\system32\ws2help.dll', no matching symbolic information found.
Loaded 'C:\WINNT\system32\OLE32.DLL', no matching symbolic information found.
Thanx
BTW as for the redirector, do you have sample code you can share... it's an important homework I would appreciate your help
mustcat
|
|
|
|
|
Hi all,
I have an application that I like to debug but I get the following error
Preloaded symbols may not match 'E:\instlsp.exe'.
Loaded 'C:\WINNT\system32\ntdll.dll', no matching symbolic information found.
Loaded '\\Farjomandi-l\Main\WINNT\system32\NTDLL.DLL', no matching symbolic information found.
Loaded 'C:\WINNT\system32\msvcrt.dll', no matching symbolic information found.
Loaded 'C:\WINNT\system32\KERNEL32.DLL', no matching symbolic information found.
Loaded 'C:\WINNT\system32\ADVAPI32.DLL', no matching symbolic information found.
Loaded 'C:\WINNT\system32\rpcrt4.dll', no matching symbolic information found.
Loaded 'C:\WINNT\system32\ws2help.dll', no matching symbolic information found.
Loaded 'C:\WINNT\system32\USER32.DLL', no matching symbolic information found.
Loaded 'C:\WINNT\system32\GDI32.DLL', no matching symbolic information found.
Loaded 'C:\WINNT\system32\OLE32.DLL', no matching symbolic information found.
The thread 0x608 has exited with code -1 (0xFFFFFFFF).
The program 'C:\RemoteDebug\LSP\Debug\instlsp.exe' has exited with code -1 (0xFFFFFFFF).
how should I setup my project setting to avoid this error and enabling me to debug my app.
thanx
mustcat
|
|
|
|
|
In my program, I allocated a 2D array and it works, the first time the function runs. The debugger seems to blame free() for some reason. The program freezes completely and seems to go into some sort of infinite loop, which is strange because the code is nowhere near an infinite loop. What could possibly be causing this?
-- Steve
|
|
|
|
|
perhaps posting your code would be a start. Why do you think it's in an infinite loop ? How do you deallocate the array ? When do you ?
See how much easier this will be when you post the code ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I am writing an application that open multiple sockets to a server. A number of threads (about 10) are each given a pointer to functions previously resolved from a DLL that handle the sockets.
My code works fine for 1-4 threads, but any more than that and WSAEnumNetworkEvents() returns a socket error. My code is in a DLL and have two global variables SOCKET* pSocket and WSAEVENT* hEvent.
I know that multiple threads cannot safely access the same value, so I made them pointers and each time a thread calls this function the new operator allocates memory to the value. Is this ok?
The code I use for socket connection is show below:
WORD wVersionRequested = MAKEWORD(2,0);
WSADATA wsaData;
int nRet;
nRet = WSAStartup(wVersionRequested, &wsaData);
if(nRet) {
WSACleanup();
return -1;
}
if(wsaData.wVersion != wVersionRequested) {
WSACleanup();
return -1;
}
LPHOSTENT lpHostEntry;
lpHostEntry = gethostbyname(lpServerName);
if(lpHostEntry == NULL) {
WSACleanup();
return -1;
}
SOCKADDR_IN sa;
sa.sin_family = AF_INET;
sa.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
sa.sin_port = htons(nPort);
pSocket = new SOCKET;
*pSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(*pSocket == INVALID_SOCKET) {
WSACleanup();
return -1;
}
hEvent = new WSAEVENT;
*hEvent = WSACreateEvent();
if(*hEvent == WSA_INVALID_EVENT) {
AfxMessageBox("WSACreateEvent()");
closesocket(*pSocket);
WSACleanup();
return -1;
}
nRet = WSAEventSelect(*pSocket, *hEvent, FD_READ|FD_CONNECT|FD_CLOSE);
if(nRet == SOCKET_ERROR) {
AfxMessageBox("EventSelect()");
closesocket(*pSocket);
WSACloseEvent(*hEvent);
WSACleanup();
return -1;
}
nRet = connect(*pSocket, (LPSOCKADDR)&sa, sizeof(SOCKADDR_IN));
if(nRet == SOCKET_ERROR) {
nRet = WSAGetLastError();
if(nRet == WSAEWOULDBLOCK) {
}
else {
closesocket(*pSocket);
WSACloseEvent(*hEvent);
WSACleanup();
return -1;
}
}
WSANETWORKEVENTS events;
while(1) {
DWORD dwRet;
dwRet = WSAWaitForMultipleEvents(1,
hEvent,
FALSE,
5000,
FALSE);
if (dwRet == WSA_WAIT_TIMEOUT) {
AfxMessageBox("Wait timed out1");
closesocket(*pSocket);
WSACloseEvent(*hEvent);
return -1;
}
nRet = WSAEnumNetworkEvents(*pSocket, *hEvent, &events);
if (nRet == SOCKET_ERROR) {
AfxMessageBox("WSAEnumNetworkEvents()");
closesocket(*pSocket);
WSACloseEvent(*hEvent);
return -1;
}
if (events.lNetworkEvents & FD_CLOSE) {
AfxMessageBox("closing...");
closesocket(*pSocket);
WSACloseEvent(*hEvent);
}
if (events.lNetworkEvents & FD_CONNECT) {
if(events.iErrorCode[FD_CONNECT_BIT]!=0)
return -1;
return 0;
}
}
return 0;
There are 10 types of people in the world
Those who understand binary, and those who don't
|
|
|
|
|
I'm trying to write a console app that I can use to feed in a user name and get back all the machines that user is ucrrently logged into by doing a query to a WINS database. But I can't seem to find any documentation whatsoever about WINS. So any links/examples/wisdom would be welcome. Thanks.
|
|
|
|
|
Anyone??? I think it could be done with the Netbios NCBFINDNAME, but am not sure how to use it. Any help whatsoever would be greatly appreciated. Thanks.
|
|
|
|
|
What is the number (not MACRO because I have VC++ 6 so I dought I have that macro defined anywhere) I would pass to GetSysColor() to retreive the color of an non-active menu item like XP displays for menu items which weren't used recently...
Now unless I was dreaming...cuz I just checked my menus in start menu and they no longer had that difference in color for not very active menu items (i must have changed it and not noticed ) these should be a color index for GetSysColor() which I can use
if not or even better still...does there exist a formula I can apply to say...GetSysColor(COLOR_BTNFACE) which will make it lighter by a certain percentage???
This would be ideal...that way my app will still work in 98 Even though i'm thinking a simple GetSysColor() call with incorrect index wouldn't crash my app...I would still feel better about it
Thanks a bunch
Cheers
I'm drinking triples, seeing double and acting single
|
|
|
|
|
Hi ...
Umm, I didn't get time to test it but I threw this together. I think it's what you want. It'll return a colour based on the colour you supply it and the value of dBrighten and bContrast. These double values are to be between 0 and 1 (0% to 100% divided by 100).
Hope this helps,
Mike
#include <math.h>
.
.
COLORREF LightenColour(COLORREF colour, double dBrighten, double dContrast)
{
const int GREY = 0x7f;
const int m_nContrast = 90;
int nStepB = (int)floor(dBrighten * GREY);
double dStepC = dContrast;
int nColourValue;
nColourValue = GetRValue(colour) + nStepB;
nColourValue = (int)floor((nColourValue - GREY) * dStepC) + GREY;
int nR = (nColourValue < 0x00) ? 0x00 : (nColourValue > 0xff) ? 0xff : nColourValue;
nColourValue = GetGValue(colour) + nStepB;
nColourValue = (int)floor((nColourValue - GREY) * dStepC) + GREY;
int nG = (nColourValue < 0x00) ? 0x00 : (nColourValue > 0xff) ? 0xff : nColourValue;
nColourValue = GetBValue(colour) + nStepB;
nColourValue = (int)floor((nColourValue - GREY) * dStepC) + GREY;
int nB = (nColourValue < 0x00) ? 0x00 : (nColourValue > 0xff) ? 0xff : nColourValue;
return RGB(nR, nG, nB);
};
|
|
|
|
|
Coolness...alot more code than I thought it would take, but still cool
Thank again
I'm drinking triples, seeing double and acting single
|
|
|
|