|
Suggestion: Your original question states that you get an exception, but you did not post the message raised by the exception. People reading your question cannot guess what that exception might be.
It's time for a new signature.
|
|
|
|
|
Hi everyone, I am working on a project that requires me to write a program which given a single word will search a database of thousands of songs and will return the artist, title, and the context in which the word appears in the song. Each song has a SongId and other meta data details and the whole database is in the form of one huge text file with a single space between two songs. I have attached an example.
I am attaching the header and cpp file containing my code to sift through the database.I have come up with a design that uses patricia trie containing all the words and array/linked list which contains all the song ids with each word in the tree referring to the SongId(s) in linked list/array that contains that word. I was also contemplating using a hash table as the song database is static. For the patricia trie I have two more linked lists containing maps of the nodes of the trees with the information regarding if the given node is a leaf or not and if it is an internal node how many eliminated nodes (as it is a patricia trie) does it store. I then intent to do a binary search on this structure to make the search even faster. I am attaching the code to my patricia tree too.
I think I know how my code is going to work but am having trouble implementing it beyond a point. I am in a roadblock and am not able to bring everything together. Hence I would truly appreciate if someone can help me with this.
Let me know if there's any other info that you want. Alternative ideas of the algorithm are welcome, though I am heavily constrained by time.
DatabaseAPICode http://www.dreamincode.net/forums/index.php?app=core&module=attach§ion=attach&attach_id=18078[^]
Patricia Tree Code http://www.dreamincode.net/forums/index.php?app=core&module=attach§ion=attach&attach_id=18079[^]
|
|
|
|
|
Good afternoon!
Taking the following into account:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[]){
int pid;
int p[2];
int q[2];
int a;
int b;
a = pipe(p);
if(a == -1)
{
fprintf(stderr, "Pipe Failed.\n");
return EXIT_FAILURE;
}
b = pipe(q);
if(b == -1)
{
fprintf(stderr, "Pipe Failed.\n");
return EXIT_FAILURE;
}
pid = fork();
switch(pid){
case -1:
perror("main: fork");
exit(1);
case 0:
printf("Child process ID: %d\n", pid);
break;
default:
printf("Parent process ID: %d\n", pid);
break;
}
getchar();
return 0;
}
The child program will execute a list of commands that it receives from the parent (via pipe p). I have a menu of commands that will run in the parent process and send the user's choice to the child for execution. The child will send the results back to the parent when done (through pipe q), so the parent process may display the results.
In the code sample I submitted, I've created both pipes, p and q. Then, I forked the child process. My question is how will the child know to recieve it's commnads through pipe p and how will the parent know to receive the results through pipe q? Should the creation of the second pipe occur later in the code than where it is located?
As always, I greatly appreciate the guidence that I have recieved while visiting forums such as this one. Any and all suggestions are welcome!
|
|
|
|
|
As it is in the code, the return address of fork is checked to determine if the control is in the child or parent process.
So if the return value is 0, it means it is the child process and so code for the child is written in case 0: and code for the parent is written in default:
Also, why do you need to create two pipes.
The pipe call returns a double ended pipe which can be used for 2 way communication.
|
|
|
|
|
Thank you very much for the reply. I know that I can use a single pipe, but my assignment is to use two different pipes, p and q.
|
|
|
|
|
can i pls get d code for "Secure multi-hop network programming with multiple
one-way key chains" in C ...plz help me out...
|
|
|
|
|
|
No, you have to grasp English first.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I agree with Chris and Carlo.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Me too, expecially with Carlo.
BTW thank you...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
holy crap!!!
other than :
<br />
int main()<br />
{<br />
return 1;<br />
}
I can't think of anything else.
Watched code never compiles.
|
|
|
|
|
slamdunk1234567 wrote: can i pls get d code
Look, please make up your mind, do you want C code or d code?
It's time for a new signature.
|
|
|
|
|
|
Excellent!
Ali
|
|
|
|
|
slamdunk1234567 wrote: pls
slamdunk1234567 wrote: plz
You kids nowadays can't even be consistent with your numb-skull-txt-speak lingo.
|
|
|
|
|
Hi,
I have a multi-thread app which can sometimes run for weeks but on occasions it hangs with the egg timer and needs to be killed with task manager. I suspect that it might be a thread deadlock but I do not know for sure. I have checked for potential deadlocks as best I can but I cant see any.
Does anyone have any suggestions how I might get more information as to where the hang occurs? Is there something I could do (in the release version) to prove it is a thread dedlock (or something else)? I have found a couple of places where I am accessing GUI objects from another thread but in my experience this usually causes a crash rather than a hang. I have corrected these now by the way but havent tried it on the target system.
Are there any tools that might help?
Any advice woud be appreciated as its driving me mad.
Thanks Tony
|
|
|
|
|
softwaremonkey wrote: I have found a couple of places where I am accessing GUI objects from another thread but in my experience this usually causes a crash rather than a hang.
Actually, deadlock (i.e., hang) is a very common symptom when one thread attempts to access another thread's UI components. The primary thread, which owns the UI, may be in a blocked state, and if the secondary thread is interacting with its UI components (e.g., sending them a message), deadlock will occur.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Thanks David, I will try to find all instances of this error but its very hard to track these and you never REALLY know that the problem has been fixed. It would be great to be able to replicate the problem then find out what's causing it.
Tony
|
|
|
|
|
You could use a debugger like Windbg to connect to the process.
Windbg has a command ~ which lists the status of all threads in the process.
|
|
|
|
|
Thanks for the reply.
I have WinDbg but I don't really understand how to use it to debug hangs. If I kill the process with Windows Task Manager I dont get a minidump yet I dont seem to be able to see any hangs if I run the app from within WinDbg (I created a test app which deliberately locks up)
Any hints and tips
Tony
|
|
|
|
|
You don't have to kill the process.
Select File -> Attach to process from the menu and attach to the already running/hung process.
|
|
|
|
|
I'm not that experienced with WinSock2 so forgive me for my bad ERROR_HANDLING.
Currently I have this line of code, breaking my application!
BytesReceived = recv(IPv4, Data, sizeof(Data), 0);
Yet I believe the worst case scenario the receive buffer would be empty and BytesReceived will be -1.
Unless their is a bigger picture missing, could you give me a heads up!
I'm currently using the HTTP protocol with blocking sockets! If you think it's a bad design strategy, please inform me!
1) send HTTP request
2) receive HTTP response
3) buffer[512] bytes, so HTTP response + data, separate them
|
|
|
|
|
What do you mean by break?
|
|
|
|
|
«_Superman_» wrote: What do you mean by break?
Die?
|
|
|
|
|
«_Superman_» wrote: What do you mean by break?
Someone said coffee break?
|
|
|
|