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...
Type: Posts; User: laserlight
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...
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...
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...
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...
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...
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?
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...
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...
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...
You forgot the part where you tell readers what you are trying to do and how does it not work.
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,...
That's pretty vague: a scanf call can have various format specifiers and various corresponding arguments. Show the code.
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...
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...
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...
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;
...
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,...
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...
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...
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...
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...
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....
What is the code of the insertTail function?
Also, did you fix printlist to take a pointer to list_t argument?
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,...
Your linked list has a head node and a tail node, which it stores as pointers to the node objects. You could do without the list object: then you would pass pointers to the head node and the tail...