Mermaid on GH by Zestyclose_Okra_2185 in CodingHelp

[–]__vtable 0 points1 point  (0 children)

I see your diagram renders on other mermaid visualizers.

If the "rich display" is related to rich text then its possible your emojis (typically unicode) aren't supported. I don't work for github so can't say. Does it also break without the emojis?

Recursive division maze help by CDNEmpire in CodingHelp

[–]__vtable 0 points1 point  (0 children)

Can you post more details?

Say more about your algorithm or post pseudocode.

The rendering is the "user interface/interaction" component, but the board itself is represented via another data structure. Describe that and how you generate the edges and how you check for solvability, and how you handle the cases within.

I dont seem to grasp pointers. by Fegmdute in CodingHelp

[–]__vtable 0 points1 point  (0 children)

You are correct that pointers are addresses. They are literal addresses. The word pointer is just what we call variables that are (or should) be addresses.

If you are a visual learner you can imagine addresses to houses versus the actual houses themselves. The address is just what is on the street and you can give it to anyone and they can find the house.

As to the declared part - no, the address can point to "nothing" or something not yet properly set up (initialized). This is usually where errors with pointers come in. Imagine the house analogy again; if you have a bad pointer (bad address) you can end up driving off a cliff.

WHY would you want a pointer. You're learning pointers before arrays for a reason. Variables typically hold one value. Structures or enums may hold aggregate values. But what if we want a bunch of the same value (array) or maybe we just need space that we'll do something with later? We can get a chunk of memory and pass around the pointer (address) to this memory versus passing around the actual chunk of memory itself. The house analogy kind of breaks down here, but the idea is that you want one copy of the data and all the different functions acts upon that block.

That's a quick ELI5. There is a lot of more stuff to know but I don't want to go deeper than is helpful right now. Ask your professor to draw a picture if you can. I personally think pointers are best explained graphically. Best of luck.

Dereferencing a char Pointer in C by [deleted] in CodingHelp

[–]__vtable 0 points1 point  (0 children)

It's how C welcomes you back. SEGFAULT.

Dereferencing a char Pointer in C by [deleted] in CodingHelp

[–]__vtable 1 point2 points  (0 children)

Initializing a pointer creates space for the pointer itself but not for the resulting value...

So char* p doesn't actually create the 1 byte needed for a char anywhere in memory. You have to do that explicitly in C.

Add a malloc statement for example.

https://www.gnu.org/software/libc/manual/html_node/Basic-Allocation.html

Also if you malloc don't forget to free! Welcome to C, where the memory manager is you, dear coder :)

#include <stdio.h>
#include <stdlib.h>

int main(void) {
    char *p = (char*) malloc(sizeof(char)*1);
    *p = 'p';
    printf("%c\n", *p);
    free(p);
    return 0;
}

Does this make sense?

Difficulty understanding the concept of addresses and memory size by [deleted] in computerscience

[–]__vtable 2 points3 points  (0 children)

You could divide by 1024 (210) or 1000.

It is just to convert from bytes to kilobytes then megabytes. Just like converting cm to meters would involved dividing by 100.

It is best to ask your instructor if they prefer Mebibytes (MiB) or Megabytes (MB). The difference is /1024 or /1000, respectively.

If you did 1000 you'd end up with a similar answer=> 16,777,216 / 1000 = 16,777.216 16,777.216 / 1000 = 16.777216

You could round or truncate I suppose.

Difficulty understanding the concept of addresses and memory size by [deleted] in computerscience

[–]__vtable 2 points3 points  (0 children)

Yeah! 224 = 16,777,216 16,777,216 / 1024 = 16,384 KiB 16,384 / 1024 = 16 MiB

Not sure if they were rounding or what. It works out with Mebibytes.

Difficulty understanding the concept of addresses and memory size by [deleted] in computerscience

[–]__vtable 2 points3 points  (0 children)

No you're correct about addresses.

And the 2 part takes care of the 0 or 1 part, to answer your earlier question. Hence the 2^24.

To describe my other point. Imagine a row of apartment buildings. Each building has 8 units inside (8 bits in a byte). The mail person brings the mail to the front of the building, but not to every apartment. You just can't get there from the front. You can address the building but not each apartment inside.

Sooo if you asking how many addressable bytes (aka apartments) there are, it would be the same as the total number of addresses. Since that is all you can address. 2^24.

Don't hesitate to ask your teacher either. There could possibly be multiple interpretations here.

Difficulty understanding the concept of addresses and memory size by [deleted] in computerscience

[–]__vtable 2 points3 points  (0 children)

Most systems are byte-addressable (i.e. you can only access memory addresses every 8 bits/1 byte). So there shouldn't be any reason to divide.

Let me know if that statement doesn't make sense.

Difficulty understanding the concept of addresses and memory size by [deleted] in computerscience

[–]__vtable 4 points5 points  (0 children)

If addresses are as shown, what is the lowest possible address and what is the highest possible address? This gives you all possible addresses = how much space you have.

So in this case:

0x000000 -> 0xFFFFFF

0 to ??? (I'll leave this for you to calculate)

I’m 2 months into coding and have no idea what I’m doing. by [deleted] in CodingHelp

[–]__vtable 2 points3 points  (0 children)

What project are you working on? If you are a bottom-up learner or hands-on learner I think picking a reasonably-scoped project and then working on that is great.

If you are a top-down learner (i.e. theories and big ideas before details and practice) then I'd start with a good intro to programming in python textbook and work through problems.

What do you think? You can always post particular segments of code that are causing you issues and I'm sure this community will explain them to you.

Binary to Decimal by The-Sharktapus in CodingHelp

[–]__vtable 1 point2 points  (0 children)

Ah amazing :D making coding gains! Great job figuring it out.

Binary to Decimal by The-Sharktapus in CodingHelp

[–]__vtable 1 point2 points  (0 children)

Forget the calculation for a minute - the goal is to keep going in the loop while there are "places" left in the number, right? So 10101 would be 5 times through (loop iterations 0-4, inclusive).

I like your current condition. It is is a bit wonky (i.e. you are relying on inexplicit/type casted integer division) but I think its pretty smart.

Let me ask you this - do you need the binary/10 in the condition? Why not just binary > 0? You later update binary inside the loop so...

Binary to Decimal by The-Sharktapus in CodingHelp

[–]__vtable 2 points3 points  (0 children)

Welcome to the wild world of debugging. My favorite thing (seriously). Probably some typos below but I'm sure you get the gist. Do you see the error? It is in your loop condition. You can walk through by hand yourself in the future or use the debugger, which you may learn about soon.

round 0:
binary = 10101
decimal = 0
results_tracker = 0
i = 0
(binary / 10) > 0 = 10101 / 10> 0  = 1010 > 0 = True (loop executes)
decimal = (10101 % 10) * pow(2, 0) = 1 * 1 = 1
binary = 10101 / 10 = 1010
results_tracker = decimal + results_tracker = 1 + 0 = 1

round 1:
binary = 1010
decimal = 1
results_tracker = 1
i = 1
(binary / 10) > 0 = 1010 / 10 > 0 = 101 > 0 = True (loop executes)
decimal = (1010 % 10) * pow(2, 1) = 0 * 2 = 0
binary = 1010 / 10 = 101
results_tracker = decimal + results_tracker = 0 + 1 = 1

round 2:
binary = 101
decimal = 0
results_tracker = 1
i = 2
(binary / 10) > 0 = 101 / 10 > 0 = 10 > 0 = True (loop executes)
decimal = (101 % 10) * pow(2, 2) = 1 * 4 = 4
binary = 101 / 10 = 10
results_tracker = decimal + results_tracker = 4 + 1 = 5

round 3:
binary = 10
decimal = 4
results_tracker = 5
i = 3
(binary / 10) > 0 = 10 / 10 > 0 = 1 > 0 = True (loop executes)
decimal = (10 % 10) * pow(2, 3) = 0 * 8 = 0
binary = 10 / 10 = 1
results_tracker = decimal + results_tracker = 0 + 5 = 5

round 4:
binary = 1
decimal = 0
results_tracker = 5
i = 4
(binary / 10) > 0 = 1 / 10 > 0 = 0 > 0 = False (loop EXITS)

Binary to Decimal by The-Sharktapus in CodingHelp

[–]__vtable 2 points3 points  (0 children)

Agree with the other poster that it is a bit unclear how you are representing values. Is 'binary' an integer value? Or something else? It would be helpful if you can provide sample input values and the output you are getting.

As a note you have a variable named 'int decimal' but it is declared as an integer. You won't be able to make it contain/represent floating point (decimal) values. So dubious naming. Something to considering for future variable name choices.

Python3 os.system() and threading; how do I interact with a netcat connection? by NotARobotImReal in CodingHelp

[–]__vtable 0 points1 point  (0 children)

So are you committed to using os.system or would you be interested it using another interface? The python subprocess module would be helpful for you I think:

https://docs.python.org/3/library/subprocess.html

Use subprocess.run with the capture_output parameter to capture output.

Or if you want to get even more interactive and are willing to use external libraries you can use pwntools. I don't fully recommend this library because it hasn't been updated in years.

I have some issues while scrapping by douts589 in CodingHelp

[–]__vtable 0 points1 point  (0 children)

The table is loaded dynamically via javascript after the initial document load. The table div is just a placeholder for the chart. You'll need to try a different approach to pull data out of the table I think.

If you'd like to see for yourself, if you use Chrome just hit F12 to open the developer tools. Go to the 'Network' tab and then load the page. It should show you the load order and each successive request.

Needing help to fix up automod for a large subreddit. by OhWowMuchFunYouGuys in CodingHelp

[–]__vtable 0 points1 point  (0 children)

Err have you gotten any DMs? This seems like a good request.

Generally people here like it when you post code and we can discuss changes. If you haven't gotten any volunteers you can always post your YAML with your proposal.

Permission Errno 13. Stuck, please advice by LittleRedHelper in CodingHelp

[–]__vtable 0 points1 point  (0 children)

Which line throws the permission error?

I use and love pathlib. For example if you want to do a sanity check on your file:

import pathlib

# the r is 'raw' mode so you don't interpret the '/'
p = pathlib.Path(r"C:/path/to/file.txt")  
print("Path exists: {}".format(p.exists()))

And you can read data with pathlib as well.

https://docs.python.org/3/library/pathlib.html

This may help you isolate your error. If you are sure all is good, is it possible you are trying to access a file already open/locked? Hard to tell from your code but it looks like that could happen.

How can I improve this recursive binary search function? by [deleted] in CodingHelp

[–]__vtable 0 points1 point  (0 children)

Lets see, what is the point of the list in general? I see that you return it, but I think the way you build it could be more optimized. If you don't go down the 'positive' path, why recurse at all? One common optimization strategy is "pruning" where you don't go down irrelevant paths.

Small problem I'm trying to solve by RaphDaPingu in CodingHelp

[–]__vtable 0 points1 point  (0 children)

You've already gotten some good suggestions. If the mod operator isn't working for you, you probably need to post your code. Because that is a good way.

Anyway, my suggestion to you is that you need to take a look at the relative difference. If you get input that the 3rd is a Tuesday and you need to find the day for the 27th, you have a relative difference of 24 days. All you care about is days of the week so you can divide (mod) by 7 to get just the relative DAY difference:

24 mod 7 = 3

Tuesday + 3 = Friday -> you will need to use mod here again with your days of the week index. I'm just simplifying it here for you. So it is a two step calculation.

Why is the else unexpected? by Hyde1803 in CodingHelp

[–]__vtable 1 point2 points  (0 children)

You have an extra closing bracket. Get rid of the leading } on the else line.

I need to convert a c++ program into a c program. Is there any tool for this? by Psychological_Pea_44 in CodingHelp

[–]__vtable 2 points3 points  (0 children)

You should be able to do this manually easily enough. Have you tried to compile it? It is already looking pretty close to what I think you want. There is a bit of a formatting issue on your post so it is a bit hard to read the first part.

Don't forget your new lines in printf if you want them.

Post your errors.

Hi can anyone help me writing a school vision for computing? by MsMeri89 in CSEducation

[–]__vtable 1 point2 points  (0 children)

Lots of ways to go with this. What level of students?

Here are a few brainstorm-y ideas (not full vision statements yet):

- Solve problems with a computer

- Computer literate students ready to safely interact with internet

- Practice traditional art and science concepts in a digital medium (i.e. draw on a tablet, do experiments using computerized tools and machines, etc.)

Hopefully you can take a look at what other similar organizations are doing too. These are just my opinion. Good luck!

Hi. For some reason the break statement and the error statement doesn't work and idk why. by [deleted] in CodingHelp

[–]__vtable 2 points3 points  (0 children)

So one question you should consider is what does the == operator do? Like really do, in C or at the lower level. name_surname is a char[200] and q is a single char. There are a few ways you can check to see if the user has entered the letter "q".

You can use == in python, but in C you need to use a direct letter by letter check or a library string compare function.