Search:

Type: Posts; User: laserlight

Page 1 of 20 1 2 3 4

Search: Search took 0.18 seconds.

  1. Replies
    1
    Views
    46

    That's a problem: your file format contains a...

    That's a problem: your file format contains a header, but you're reading it as if there was no header.

    I might suggest parsing it like this:

    int read_coords(FILE *fptr, struct Coord coords[],...
  2. Perhaps you meant "theoretically" rather than...

    Perhaps you meant "theoretically" rather than "practically". In practice, you of course do not have unlimited space since it is limited both by hardware and the fact that the space allocated needs to...
  3. Replies
    3
    Views
    138

    You probably want to declare the array pointer...

    You probably want to declare the array pointer earlier: makes no sense to declare it in that inner loop in the middle of parsing since you want to parse the current item and assign it to the relevant...
  4. Replies
    3
    Views
    138

    malloc(sizeof(char)) allocates space for exactly...

    malloc(sizeof(char)) allocates space for exactly one char, so if you're trying to use it as a string, it can only store an empty string. But then you overwrite it with strdup, so you end up with a...
  5. Replies
    16
    Views
    367

    You are mistaken. result is an array of 200 char,...

    You are mistaken. result is an array of 200 char, not a pointer to char. It is true that in many cases it is implicitly converted to a pointer to its first element, but in this case that does not...
  6. Replies
    16
    Views
    367

    Ugh, hope you get that figured out. Between my...

    Ugh, hope you get that figured out. Between my personal laptop and my work laptop I'm effectively triple booting Mac, Linux, and Windows hahaha


    That's a good point, but it does involve a...
  7. Replies
    16
    Views
    367

    Since deathmetal appears to want to loop and...

    Since deathmetal appears to want to loop and seems to have a maximum length in mind, wouldn't it make more sense to use snprintf if you're taking that approach rather than just concatenating?
  8. Replies
    16
    Views
    367

    You must have missed the part where I explained...

    You must have missed the part where I explained that it is less efficient than deathmetal's original code, which itself is not too bad where efficiency is concerned. If the aim is to be efficient...
  9. The problem is that fwrite writes the struct...

    The problem is that fwrite writes the struct object member-wise, so if it has a pointer member, it writes the value of the pointer, i.e., an address, not what the pointer points to. You could change...
  10. Replies
    16
    Views
    367

    I might suggest something like this: #include...

    I might suggest something like this:

    #include <stdio.h>
    #include <string.h>

    char *join_by_char(char *dest, size_t dest_maxlen, const char *left, char glue, const char *right)
    {
    size_t...
  11. Replies
    7
    Views
    269

    You forgot the part where you tell readers what...

    You forgot the part where you tell readers what you are trying to do and how does it not work.
  12. You start off with n elements as the size of the...

    You start off with n elements as the size of the array. If there are any duplicates, after removing them, the size of the array would surely be less than n, but you did not update the value of n,...
  13. That's pretty vague: a scanf call can have...

    That's pretty vague: a scanf call can have various format specifiers and various corresponding arguments. Show the code.
  14. What you need to do is to compile at a high...

    What you need to do is to compile at a high warning level, and pay attention to warnings. Actually, even at a low warning level your compiler is probably warning you about a typo error in your third...
  15. I already told you: do a linear search of the...

    I already told you: do a linear search of the entire linked list.

    If you find this too difficult, try another problem first: find the smallest number in the linked list.

    EDIT:
    I'd also suggest...
  16. It sounds pretty straightforward since you...

    It sounds pretty straightforward since you already have an idea: what you're doing is finding the least number greater than the given number, so a linear search of the entire linked list should do...
  17. Replies
    33
    Views
    706

    Congratulations, it looks like you've implemented...

    Congratulations, it looks like you've implemented a working solution. I might tweak it a bit:

    void insertTail(list_t *list, node_t *node)
    {
    node->prev = list->tail;
    node->next = NULL;
    ...
  18. Replies
    33
    Views
    706

    You have it backwards. "Next" means "being the...

    You have it backwards. "Next" means "being the first one after the present one or after the one just mentioned". The next pointer links to the node after the current node, not the node before it,...
  19. Replies
    33
    Views
    706

    You have the right idea to treat the empty linked...

    You have the right idea to treat the empty linked list separately from a linked list that already has nodes. However, you have indeed made a mistake for the case where the linked list already has one...
  20. Replies
    33
    Views
    706

    If you excuse the ASCII art, this is how your...

    If you excuse the ASCII art, this is how your final diagram should look if you append 6 and then append 7 ("append" means "insert at the end", i.e., for a linked list it means "insert after the...
  21. Replies
    33
    Views
    706

    Ah, I should have been clearer: the head and tail...

    Ah, I should have been clearer: the head and tail boxes are meant for you to keep track of what is the head and what is the tail. You should not draw any arrows to them because they represent...
  22. Thread: Composition

    by laserlight
    Replies
    11
    Views
    688

    Ah, I see. When I was reading through it...

    Ah, I see. When I was reading through it previously, I was thinking that this was a bad idea to introduce so early in that tutorial, and it appears that my hunch was correct. As much as I am happy to...
  23. Replies
    33
    Views
    706

    Excellent. Now here's what you need to do: take a...

    Excellent. Now here's what you need to do: take a sheet of paper and a pencil. Pretend that you're executing your insertTail function, but on paper. So you draw a box, and put in 6 for the value....
  24. Replies
    33
    Views
    706

    What is the code of the insertTail function? ...

    What is the code of the insertTail function?

    Also, did you fix printlist to take a pointer to list_t argument?
  25. Replies
    33
    Views
    706

    Nodes don't have tails. What this does is set the...

    Nodes don't have tails. What this does is set the prev pointer of the node to be the tail of the linked list. This means that we're about to make this node the new tail of the linked list.


    Yes,...
Results 1 to 25 of 500
Page 1 of 20 1 2 3 4