Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are lots of ways to handle it... You can use arrays, via dynamic memory allocation, with realloc, if you feel brave enough to try.</p> <p>The standard implementation of qsort, though, needs each element to be a fixed length, which would mean having an array-of-pointers-to-strings.</p> <p>Implementing a linked list, though, should be easy, compared to using pointers to pointers.</p> <p>I think what you were told to do was not to save the strings as list; but <em>in</em> a linked list:</p> <pre><code>struct node { char *string; node *next; } </code></pre> <p>Then, all you have to do is, every time you read a string, add a new node into the list, in its ordered place. (Walk the list until the current string's length is greater than the string you just read.)</p> <p>The problem of words not being a fixed length is common, and it's usually handled by storing the world temporarily in a buffer, and then copying it into a proper length array (dynamically allocated, of course).</p> <p><strong>Edit:</strong></p> <p>In pseudo code:</p> <pre><code>array = malloc(sizeof(*char)) array_size = 1 array_count = 0 while (buffer = read != EOF): if(array_count == array_size) realloc(array, array_size * 2) array_count++ sring_temp = malloc(strlen(buffer)) array[array_count] = string_temp qsort(array, array_count, sizeof(*char), comparison) print array </code></pre> <p>Of course, that needs a TON of polishing. Remember that array is of type <code>char **array</code>, ie "A pointer to a pointer to char" (which you handle as an array of pointers); since you're passing pointers around, you can't just pass the buffer into the array.</p>
    singulars
    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.
    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