![]() |
| | #1 |
| Registered User Join Date: Feb 2009
Posts: 58
| Problem going from Linux to jGrasp Code: Exiting due to signal SIGSEGV General Protection Fault at eip=00004738 eax=74736e53 ebx=000001a2 ecx=74736e69 edx=000929ac esi=00000054 edi=00011f64 ebp=00091e78 esp=00091e78 program=H:\PROJECTS\PROJECT3\A.EXE cs: sel=01a7 base=01a20000 limit=0009ffff ds: sel=01af base=01a20000 limit=0009ffff es: sel=01af base=01a20000 limit=0009ffff fs: sel=017f base=000059a0 limit=0000ffff gs: sel=01bf base=00000000 limit=0010ffff ss: sel=01af base=01a20000 limit=0009ffff App stack: [00091f64..00011f64] Exceptn stack: [00011ec0..0000ff80] Call frame traceback EIPs: 0x00004738 0x000022a0 0x000022c3 0x00002241 0x0000204a 0x00001f36 0x00003d38 ----jGRASP wedge2: exit code for process is 255. ----jGRASP: operation complete. Some were talking about needing to download a dll. Some were talking about debugging. My code is here: Code: #include <stdio.h>
#include <stdlib.h>
typedef struct node NODE;
typedef NODE* NODEPTR;
struct node
{
char word[10];
NODEPTR Parent;
NODEPTR RightChild;
NODEPTR LeftChild;
};
NODEPTR makeNode();
NODEPTR chooseRoot(NODEPTR, NODEPTR, NODEPTR);
void makeTree(NODEPTR, NODEPTR);
void readFile();
void getWord(NODEPTR);
void destroyTree(NODEPTR, NODEPTR);
void searchTree(NODEPTR, NODEPTR);
int main()
{
readFile();
return;
}
void readFile()
{
NODEPTR rootNode = NULL;
NODEPTR tempNode1 = NULL;
NODEPTR tempNode2 = NULL;
NODEPTR tempNode3 = NULL;
NODEPTR xNode = NULL;
FILE *file;
char word[10];
file = fopen("inData.txt", "r");
if(file == NULL)
{
printf("\nError opening input file ...Program Terminating");
eixt(1); //changed this to return; and it did nothing
}
{
tempNode1 = makeNode(); //call
tempNode2 = makeNode(); //call
tempNode3 = makeNode(); //call
fscanf(file, "%s", tempNode1->word);
fscanf(file, "%s", tempNode2->word);
fscanf(file, "%s", tempNode3->word);
rootNode = chooseRoot(tempNode1, tempNode2, tempNode3); //call
}
xNode = makeNode(); //call
fscanf(file, "%s", xNode->word);
while(!feof(file))
{
makeTree(rootNode, xNode); //call
xNode = makeNode(); //call
fscanf(file, "%s", xNode->word);
}
xNode = makeNode();
getWord(xNode);
searchTree(rootNode, xNode); //call
destroyTree(rootNode, rootNode); //call
return;
}
void getWord(NODEPTR xNode)
{
char word[10];
printf("Enter the word you want to search for.\n");
scanf("%s", xNode->word);
return;
}
NODEPTR makeNode()
{
return malloc(sizeof(NODE));
}
NODEPTR chooseRoot(NODEPTR tempNode1, NODEPTR tempNode2, NODEPTR tempNode3)
{
/*if(tempNode1->word == '\0' || tempNode2->word == '\0' || tempNode3->word == '\0')
{
printf("Error, not enough data...exiting");
exit(1); //this part of the function is commented out
}*/
if((strcmp(tempNode1, tempNode2)>0 && strcmp(tempNode1, tempNode3)<0) || (strcmp(tempNode1, tempNode2)<0 && strcmp(tempNode1, tempNode3)>0))
{
makeTree(tempNode1, tempNode2); //call
makeTree(tempNode1, tempNode3); //call
return tempNode1;
}
if((strcmp(tempNode2, tempNode1)>0 && strcmp(tempNode2, tempNode3)<0) || (strcmp(tempNode2, tempNode1)<0 && strcmp(tempNode2, tempNode3)>0))
{
makeTree(tempNode2, tempNode1); //call
makeTree(tempNode2, tempNode3); //call
return tempNode2;
}
makeTree(tempNode3, tempNode1); //call
makeTree(tempNode3, tempNode2); //call
return tempNode3;
}
void makeTree(NODEPTR rootNode, NODEPTR xNode)
{
if(strcmp(xNode->word, rootNode->word) > 0 && rootNode->RightChild != NULL)
{
makeTree(rootNode->RightChild, xNode); //call
}
if(strcmp(xNode->word, rootNode->word) < 0 && rootNode->LeftChild != NULL)
{
makeTree(rootNode->LeftChild, xNode); //call
}
if(strcmp(xNode->word, rootNode->word) > 0 && rootNode->RightChild == NULL)
{
rootNode->RightChild = xNode;
xNode->Parent = rootNode; //call
}
if(strcmp(xNode->word, rootNode->word) < 0 && rootNode->LeftChild == NULL)
{
rootNode->LeftChild = xNode;
xNode->Parent = rootNode; //call
}
return;
}
void searchTree(NODEPTR rootNode, NODEPTR xNode)
{
if(strcmp(xNode->word, rootNode->word) == 0)
{
printf("Found it!\n");
return;
}
/*if(rootNode->RightChild == NULL && rootNode->LeftChild == NULL)
{
printf("Couldn't find it!\n");
return;
}*/
if(strcmp(xNode->word, rootNode->word) < 0 && rootNode->LeftChild != NULL)
{
searchTree(rootNode->LeftChild, xNode);
return;
}
if(strcmp(xNode->word, rootNode->word) > 0 && rootNode->RightChild != NULL)
{
searchTree(rootNode->RightChild, xNode);
return;
}
printf("Word was not found.");
return;
}
void destroyTree(NODEPTR rootNode, NODEPTR xNode)
{
NODEPTR temp = NULL;
char word[10];
if(rootNode->RightChild == NULL && rootNode->LeftChild == NULL)
{
free(rootNode);
return;
}
if(xNode != NULL)
{
if(xNode->LeftChild != NULL)
{
destroyTree(rootNode, xNode->LeftChild); //call
return;
}
if(xNode->RightChild != NULL)
{
destroyTree(rootNode, xNode->RightChild); //call
return;
}
if(xNode->RightChild == NULL && xNode->LeftChild == NULL)
{
temp = xNode;
xNode = xNode->Parent;
if( strcmp(temp->word, xNode->word) < 0)
{
free(temp);
xNode->LeftChild = NULL;
destroyTree(rootNode, xNode); //call
return;
}
if( strcmp(temp->word, xNode->word) > 0)
{
free(temp);
xNode->RightChild = NULL;
destroyTree(rootNode, xNode); //call
return;
}
}
}
}
Any1 ever deal with this crap? Last edited by madmax2006; 11-11-2009 at 01:24 PM. |
| madmax2006 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problem with fork command after solaris to Linux porting | amit.arali | Linux Programming | 7 | 07-21-2009 11:48 PM |
| OpenGL Linux Line Drawing Problem | swanley007 | C++ Programming | 2 | 04-03-2006 09:31 AM |
| Problem with porting of Linux code to Windows, FORTRAN/C. | stormlab | C Programming | 1 | 10-18-2005 10:20 AM |
| Problem with C++ in linux | MelaOS | C++ Programming | 2 | 12-28-2003 06:29 AM |
| Linux modem problem | VooDoo | Linux Programming | 5 | 08-19-2002 05:34 AM |