BST dictionary error?
<p>I'm building a BST dictionary tree. I'm getting an error at the <code>strcmp</code> line but i have no idea why. the error is <code>EXC_BAD_ACCESS(Code = 1)</code>. This tree would be just a right tree because the first line of the file is <code>a</code> so it would be the root with no left children. I commented beside the line of the error.</p>

<p>first couple of lines from text;</p>

<pre><code>a   un, uno, una[Article]
aardvark    cerdo hormiguero
aardvark    oso hormiguero[Noun]
aardvarks   cerdos hormigueros
aardvarks   osos hormigueros
</code></pre>

<p>my code;</p>

<pre><code>#include &lt;stdio.h&gt;


typedef struct node{
    char lineOfChar[200];
    struct node *left;
    struct node *right;
}BST;

typedef struct nodeSec{
    BST *next;
}mainLink;

int main(int argc, const char * argv[]) {

    struct node *head = malloc(sizeof(BST)); //Define the Head of the linked list of BST
    struct nodeSec *headOfHead = malloc(sizeof(mainLink));
    headOfHead-&gt;next = head;
    struct node *current = &amp;head; //Progress down the tree
    FILE *file;
    file = fopen("/Users/bassammetwally/Desktop/Homework5/text","r");
    int times = 0;
    char arrayOfLine[200];

    while(fgets(arrayOfLine, 200, file)){ //While loop to read lines into the node's array

        if (times == 0) // head of linked list to run once
        {
            for (int counterFirstTime = 0; counterFirstTime &lt; 140; counterFirstTime++)
            {
                head-&gt;lineOfChar[counterFirstTime] = arrayOfLine[counterFirstTime]; // copy the array into the node array
            }
            times++; // increase times so the previous block would not repeat
        }
        else {

            struct node *temp = malloc(sizeof(BST)); //start a temp node to store the current information for further sorting
            for (int counterFirstTime = 0; counterFirstTime &lt; 40; counterFirstTime++)
            {
                temp-&gt;lineOfChar[counterFirstTime] = arrayOfLine[counterFirstTime];//copying line into the node array
            }
            int q = 2;
            while (q == 2)
            {
                int characterCompare;
                if (head != NULL &amp;&amp; temp != NULL)
                {
                characterCompare = strcmp(temp-&gt;lineOfChar, head-&gt;lineOfChar);//compares the two characters of the array WHERE I GET THE ERROR
                }

                if (characterCompare &gt; 0) // if temp is bigger..
                {
                    current = head;
                    head = head-&gt;right;// go to the right of the tree
                    if (head == NULL)// if its NULL and empty then just store it there
                    {
                        head = malloc(sizeof(BST));
                        head = temp;
                        current-&gt;right= head;
                        break;
                    }
                }
                else if (characterCompare &lt; 0){ //since there will not be any duplicates
                    current = head;
                    head = head-&gt;left;
                    if (head == NULL)// if its NULL and empty then just store it there
                    {
                        head = malloc(sizeof(BST));
                        head = temp;
                        current-&gt;left = head;
                        break;
                    }
                }
                else if( characterCompare == 0)
                {
                    continue;
                }

            }
        }
        head = headOfHead-&gt;next;
    }
    return 0;
}
</code></pre>