Hot answers tagged

2

I thought about this as well today, and your answer to your own question is right. We malloc heap memory to permanently (until you free it once the programme has ended) store a new node. The return value is a pointer to this new node, as in node* new_node = malloc(sizeof(node)); If we didn't do that, and instead just used node, as you suggested, the memory ...


2

The website is available on https://ide50-username.cs50.io/ I had the same problem. Try update50 in console.


1

Your answers is going to be a list of each list of answers (ie, a list of rows). The actual 'title' of those answers isn't in the file. You only need to iterate over each line and then iterate over each item (in the comma separated list). Let's say that someone filled out your form and chose "me, 1, sports, my reasons" for the 4 questions. The next ...


1

If your workspace is public, it is accessible to anyone on the web without your login details. You can see the setting in CS50IDE -> Go To Your Dashboard. I reserve the right to change/delete my answer if you discover that your workspace is public. Further, by no means am I suggesting that your workspace should be public. I believe it should be private.


1

It can be found here. In general, edX: You can find the source code in Courseware tab > Week X > Lecture / Lecture, continued > scroll down to below the video under Source Code. Everyone: You can also go to http://cs50.tv/2013/fall/ (or whatever semester you're watching), Lecture tab > Week X > Monday/Wednesday > Source Code.


1

Absolutely correct. If search() is the first operation called then the first node variable will be NULL and the loop will not execute. However, if you inspect the code for insert(), you may see that a value is assigned to the first node. For example, from line 123: // initialize node printf("Number to insert: "); newptr->n = GetInt(); newptr->next = ...


1

I am confused as to why these are both called n. As a result, the line of the search function Why are they both n? Well, they could have been called anything he wanted. This was just for demonstration purposes (no time to think about names). aren't these two n's two different things? Yes, they are different variables. And what he's basically doing here is ...


1

It's common to use the variable n when we are talking about numbers. That example also help you to realize that even when those data are receiving the same variable name, they won't collide because they have different scopes (you have to check inside the ptr node to compare if the value n inside it is equal to the value n in main.


1

The only reason that GetInt() would return "Retry" is if it recieved a non-integer from standard input (ie, from your keyboard), as the definition says: /* * Reads a line of text from standard input and returns it as an * int in the range of [-2^31 + 1, 2^31 - 2], if possible; if text * does not represent such an int, user is prompted to retry. Leading ...


Only top voted, non community-wiki answers of a minimum length are eligible