|
Can anyone please tell me why this code code gives a segmentation? The
class NonLeafTrieNode<br />
{<br />
public:<br />
NonLeafTrieNode(){};<br />
NonLeafTrieNode(char);<br />
<br />
private:<br />
friend class Trie;<br />
<br />
NonLeafTrieNode **ptrs;<br />
char *letters;<br />
int endOfWord;<br />
bool isLeaf;<br />
};
The code below are in the Trie class and I use this to access the isLeaf variable in the class.
int flag = p->ptrs[pos]->isLeaf;<br />
if (!(pos == -1) && flag)
If I keep the isLeaf variable a boolean the code gives a segmentation fault, but whenever I make it a integer the code works perfectly.
Can anyone tell me why this happens.
Thanks a lot
LiquidE_SA
|
|
|
|
|
A very strange bug; sounds to me like some kind of memory access splat. There's not too much to go on from your example, but the fact you're using an array (ptrs[]) and that changing the size of the class (by changing bool to int [see note]) causes a crash, sounds to me like something somewhere isn't accessing the right memory.
Ensure you've allocated enough memory for ptrs[] and that 'pos' is in within a valid range - if that doesn' solve it perhaps post a bit more information - whereabouts is the crash? I assume it's on the 'p->ptrs[pos]->isLeaf' line.
Matt Godbolt
Engineer, ProFactor Software
StyleManager project
|
|
|
|
|
|
I have one function with 3 parameters.
In that function I have one switch case statement which depends on first parameter of my function. Nearly the cases are 28 to 30. For each case there is another sub switch case which depends on the second parameter of my function with more cases. For different cases I am allocating different classes memory in one class object. At last the function returning that object. For this concept implementation is there any simple implementation or any other logic, any template. The cases are increasing because of new implementations. Expecting some better solution.
The sample code is:
CMyCls* CEmr:GetCls(DWORD dwDId, DWORD dwClsId,BOOL bFe)
{
CMyCls* pCls = NULL;
switch (m_byClsFamily)
{
case _FAMILY_1_:
switch (dwClsId)
{
case 0x8242:
if (bFe || (dwDId == DB_18C453))
pCls = new CMyCls1;
break;
case 0x8252:
if (bFe || (dwDId == DB_18C452))
pCls = new CMyCls2;
break;
...
...
}
break;
case _FAMILY_2_:
...
case _FAMILY_3_:
...
case _FAMILY_4_:
...
...
break;
}
return pCls;
}
Here All CMyCls1, CMyCls2, CMyCls3, CMyCls4,... all are derived from a class named "CMyCls".
My actual problem is, I need to simplify my switch case. I am searching for the easyest way even the cases may be increased in near future. In different case I need to create different Calss's object. Creating object is not a problem. But the switch case becomeing very big. I am looking for any good template or any other solution.
Any help very thankful to them. It is urgent.
Nice talking to you.
|
|
|
|
|
Hi, everybody!
I am trying to build a numerical simulation which stores data in a mat-file. My program was written by C++ and runs on Linux. I want to store output data in mat-file because it's convenient to analyze in matlab. I don't know how to write the data to a mat-file and how to buid a C++ program integrated with matlab in Linux.
Please help me.
Thanks a lot!
h
|
|
|
|
|
Hello, guys!
I'm not found at the WEB any good link with example of implementation of DirectShow's DVD seeking. How I can correctly perform DVD (also VOB files) seeking with Direct Show Interface?
Thanks.
|
|
|
|
|
I m not getting how to run music or .bmp files in c++. I have a bit of idea that a third party tool will be needed in doing that, but I dont know exactly how it is done. Please if any body can sort out this problem.
Inder Gujral
|
|
|
|
|
try createprocess.
-prakash
|
|
|
|
|
This was a very stupid answer.Createprocess will not help at all in linkin the audio driver with compiler.
|
|
|
|
|
Hai friends,
Anyone there to help me to kill a process running in task manager using VC++ or C++.. i cant proceed my my work without this solution... past three days i was back of this.. plz help me
Regards
Hareesh
|
|
|
|
|
|
Its really bad that you have kill a process to get your work done unless that is not your developed process.
-prakash
|
|
|
|
|
Hello..
I'm trying to read in data coming from the serial port.. the data can come in at any time (so the program has to monitor the serial port continuously, thats why i'm using a while loop in my code below). I'm reading Tag IDs (strings) which are formatted into packets.. each packet starts with the '&' character and ends with the '$' character..
Right now I read in the whats coming from the serial port (using a infinite while loop) into a string and then tokenize that string according to my packet delimiters.. the problem is that Readfile is returning after getting part of the tag ID packet and then the remaining part of the tag ID packet comes the next time the while loop is called.. I think its something to do with the way I use the readfile function in the while loop..my code is given below.. Please advice..
Thank you for your help..
<br />
<br />
char buffer[200000];<br />
<br />
while (true)<br />
{<br />
printf("In while\n"); <br />
<br />
memset(buffer, 0, sizeof(buffer));<br />
if (ReadFile(h, buffer, sizeof(buffer)-1, &bytesRead, 0))<br />
{<br />
printf("Read file has a result\n"); <br />
if (bytesRead != 0)<br />
{<br />
printf("Got some bytes\n"); <br />
printf ("%s", buffer);<br />
<br />
printf( "Tokens in buffer:\n" );<br />
<br />
token = strtok(buffer, "&$" );<br />
<br />
while( token != NULL )<br />
{<br />
<br />
printf( " %s\n", token );<br />
<br />
token = strtok( NULL, "&$" );<br />
}<br />
<br />
}<br />
<br />
else <br />
{<br />
printf("No bytes read\n"); <br />
}<br />
}<br />
<br />
else {<br />
printf("Readfile didnt give proper result \n"); <br />
}<br />
Sleep(200);<br />
}<br />
<br />
|
|
|
|
|
Hi all -
My project requirement says to create a daemon program to communicate with a DLL for data exchange. I have some questions regarding the daemon program. Any pointers would be helpful.
1. Daemon is equivalent to "Services" in Windows? A service can be non web-based as well? (I search on internet, I find only web based services every where)
2. How do you create these services in Visual Studio 6.0.
which technology you use?
3. Is the service going to be an ATL COM+ based service?
4. Any articles, knowledge base in internet for these?
Thanks in advance
Misha
|
|
|
|
|
misha_grewal wrote:
1. Daemon is equivalent to "Services" in Windows? A service can be non web-based as well? (I search on internet, I find only web based services every where)
yes, it is.
misha_grewal wrote:
How do you create these services in Visual Studio 6.0.
which technology you use?
you can use ATL wizard.
misha_grewal wrote:
Any articles, knowledge base in internet for these?
http://www.codeproject.com/system/windows_nt_service.asp#xx490705xx[^]
|
|
|
|
|
Hello, I basically want to make a function that will take in any interator and perform operations on it. For example, if I had the function: >mySort( iterator, iterator ) I would be able to pass in a std::vector iterator, a std::set iterator, a std::list or any iterator defined for a customized container, or any other STL container. Is this possible??
Mike - I love to program!
|
|
|
|
|
allenmpcx wrote:
Is this possible??
Yes, but it needs to be a template function, not a function. For examples, see standard algorithms[^].
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
-- modified at 21:47 Wednesday 28th September, 2005
|
|
|
|
|
These are all good, however when I try to take the ideas and implement them, I get errors, or they don't work correctly. Are there any examples that would do a simple sort using iterators only??
Mike - I love to program!
|
|
|
|
|
|
template< class Iter ><br />
void InsertionSort( Iter first, Iter last )<br />
{<br />
Iter step;<br />
Iter i;<br />
for( step = first; step < last; step++ )<br />
{<br />
Iter temp = first;<br />
for( i = step; i >= first; i = (i-first) )<br />
{<br />
if( (*temp) < (*(i-first)) )<br />
{<br />
(*i) = (*(i-first));<br />
}<br />
else<br />
{<br />
break;<br />
}<br />
}<br />
(*i)=(*temp);<br />
}<br />
}
I'm trying to make it so I can pass in any iterator from any container, however this won't even compile.
Mike - I love to program!
|
|
|
|
|
allenmpcx wrote:
however this won't even compile
and the compiler says...???
(please be complient and provide all the infos that could help man)
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
I was actually able to fix the previous problem by implementing std::iterator_traits< typname Iter >, however, is there a way to make a quicksort algorithm using iterators? I saw lots and lots of implementations using integers, but I need my quicksort algorithm to accept an iterator from the list or a vector. Is this possible?
Mike - I love to program!
|
|
|
|
|
Hi, i'm a newbie programmer fascinated by the inner workings of search engines. I would like to know if any one has an idea what language(s) would a search engine like google use, and what language would you use if you were planning to create a very very basic web search engine. And also, and since i'm a C++ programmer, I wanted to know if C++ could play any role in this job!
|
|
|
|
|
Silly answer: Google specifically uses pigeons! .
Real answer - I suspect google and the like use C and C++ as their mainstay for the actual search technology. No evidence to back this up, mind. I do know that Google use Python as their script language; indeed their support forum pages seem to run exclusively in Python.
As for implementing itself - it's a daunting task. First you need a way of getting the data. You'll need a way of querying many web sites and storing the pages in an indexable way - as Patricia_tries, or one of many many other clever ways of storing data for searching. You'll need a huge amount of storage for this kind of thing - I dread to think how big Google's databases are. You'll also need a lot of internet bandwidth to suck in all the pages you want to index. Of course, if you're only interested in learing about how these things work, you can scale back and just index say one site. For that, you could build a little SQL database of all the words on the site linking to the page the words are found on, etc. This 'spider' program is an ideal candidate for a C/C++ application.
Then you need a way of searching through the data; a web application is usually the way to present web searches. Either write a cgi-bin script for your web server (e.g. Apache) or implement it as a plugin directly to the web server. Or, if you're just more interested in getting something up and running quickly, perhaps consider Python, PHP or Perl extensions to your web server, querying the SQL database you made in part 1.
Hope that helps - happy coding!
Matt Godbolt
Engineer, ProFactor Software
StyleManager project
|
|
|
|
|
Hello! I have just started to learn about linked list and would like to try to insert a set of random numbers into a linked list. I'm confused as to how to go about. I can insert a single number but dont have a clue as to how to do it with set of number. thanks for the help.
|
|
|
|