Note that there are some explanatory texts on larger screens.

plurals
  1. POusing arrays as hashTables
    primarykey
    data
    text
    <p>i am trying to use arrays as hashtable, each array ponits to its own linked list</p> <p>the size is to check that the number of nodes of the linked list is 32.</p> <p>my problem here is that i get segmentation fault, but i cant see any error in my pointers, here is the full code.</p> <pre><code> #include &lt;stdio.h&gt; #include &lt;malloc.h&gt; #include &lt;stdlib.h&gt; #include &lt;time.h&gt; typedef int bool; enum { false, true }; void main(int argc, char *argv[]) { // create linked list--------------------------- struct node { int num; struct node *ptr; }; typedef struct node NODE; NODE *first, *last, *temp, *newNode=0 ; int count = 0; first = NULL; last=NULL; temp=NULL; newNode=0; //----------------------------------------------------------------------- //filling the text file with billions of integers------------------------------------------------ FILE *f = fopen("file.txt", "w"); if (f == NULL) { printf("Error opening file!\n"); exit(1); } int i = 0; unsigned long long randomvalue; for (i = 0; i &lt; 10000000; i++) { randomvalue = random(); randomvalue &lt;&lt;= 16; // just picked 16 at random randomvalue ^= random(); // you could also use + but not "or"; randomvalue %= 10000000000ULL; fprintf(f,"%lld \n",randomvalue); } fclose(f); NODE* array[312500]; first = (NODE *)malloc(sizeof(NODE)); last= (NODE *)malloc(sizeof(NODE)); temp = (NODE *)malloc(sizeof(NODE)); newNode = (NODE *)malloc(sizeof(NODE)); FILE *file = fopen ("file.txt", "r"); int x=0; for ( x=0; x&lt;=312500; x++) { while (count &lt;=32) { fscanf (file, "%d", &amp;temp-&gt;num); temp-&gt;ptr=NULL; newNode-&gt;num=temp-&gt;num; newNode-&gt;ptr=NULL; if (first != 0) { last-&gt;ptr=newNode; last=newNode; count=count+1; } else { first = newNode; last = newNode; count=count+1; } fflush(stdin); newNode-&gt;ptr=0; newNode=NULL; } count =0; array[x]-&gt;ptr=first; first-&gt;ptr=0; first=NULL; last-&gt;ptr=0; last=NULL; } fclose (file); temp-&gt;ptr = 0; temp=NULL; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload