kzidane
Moderator
  • Member for 7 years, 7 months
  • Last seen more than a week ago
(Hacker2) Why am I getting a seg fault here from fgets?
Accepted answer
1 votes

Not really. The cause of the error involves some topics that you will study later in the course. I'll try to simplify my answer as much as possible, but don't panic if you don't fully understand what ...

View answer
pset8 pickup unable to access the values of the shuttle.seats
Accepted answer
1 votes

You are over-complicating things a little. First you're creating an array of one object. So the correct way to access the value of name in your example is shuttle.seats[j][0].name; Second, you ...

View answer
Dynamic string length allocation in new_node->word; array type char [46] is not assignable
2 votes

You are confusing things here. First, according to the manual page of realloc Unless ptr is NULL, it must have been returned by an earlier call to malloc(), calloc() or realloc(). That is ...

View answer
Am I creating an array of pointers or an array of structs?
Accepted answer
1 votes

Does node* hashtable[500]; create an array of pointers or does it create an array of nodes ? It creates an array of node *s (otherwise known as pointers to nodes). The array declaration above does ...

View answer
Why isn't a dereference operator used when doing File I/O in C
Accepted answer
0 votes

If you executed man fputs in the terminal, you would find that fputs takes a char * and a FILE * not a FILE. You can still access the data through a pointer. In fact, this is what fputs is likely to ...

View answer
PSET6: Load segfaults when I try to access variable in node
Accepted answer
1 votes

To understand the cause of the error, you should understand the semantics of the assignment operator (i.e., =). It simply assigns the value on its right to the variable on its left. When you did ...

View answer
Cannot get drop down menu to display for pset7. Why would this be?
Accepted answer
4 votes

The request method is GET by default. When the user visits http://pset7/sell.php, she is requesting the page (i.e., sell.php in this case) using GET. Therefore, the condition $_SERVER["REQUEST_METHOD]...

View answer
Algorithm to count 729 students in the classroom
2 votes

Suppose each [1] represents a standing person that carries a value (in this case, everybody carries 1). [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] [1] ...

View answer
Can I create and initialize arrays of other types the same way I can create and initialize char arrays?
Accepted answer
0 votes

I don't think this is the question you should ask since you could simply have an answer to it by opening up a text editor, writing the code you want and then try to compile it see if it compiles or ...

View answer
How is Week 9 SQL Atomocity solved?
Accepted answer
2 votes

I think the professor was referring to the process of updating when he analogized this to a SELECT query and an INSERT query at the same time, because that's probably how you'd probably do an update ...

View answer
Declaring and Using an argument in a while loop
Accepted answer
0 votes

An argument is a variable/ a value that is passed to a function when it's called. It actually has nothing to do with what you're describing. Now, for your question, you could actually do something ...

View answer
How are associative arrays like hash-tables?
Accepted answer
0 votes

A hash-table basically maps keys to values (it basically consists of these two parts — the keys part and the values part). If you used a hash-table in pset6, you'd probably know that you had to ...

View answer
Declaration and Initialization gives error: unused variable
1 votes

You never really used k in main after you've declared it. This error is actually caused by passing the -Werror option on compilation which is responsible for turning warnings to errors. To fix that ...

View answer
The difference between the format of houses.js and passengers.js
Accepted answer
1 votes

You can think of HOUSES as an associative array. It contains key/value pairs. The keys are the strings (e.g., "Adams House", "Cabot House", etc.) and the values are the objects that are mapped to ...

View answer
What does 'random access' mean?
2 votes

From Wikipedia, In computer science, random access (more precisely and more generally called direct access) is the ability to access an item of data at any given coordinates in a population of ...

View answer
Recover Buffer as uint8_t instead of int
Accepted answer
7 votes

A variable of type int is 4 bytes long on most 32-bit operating systems. If you declared your buffer to be an array of 512 ints, this means that the size of your array is 2048 bytes (4 blocks) rather ...

View answer
trie does not assign pointers correctly in load and produces seg fault
Accepted answer
1 votes

First, you're getting a segmentation fault because you're trying to access ptr->children[position] without making sure that ptr itself is NULL in which case a segmentation fault is caused (because ...

View answer
Polygon paddle instead of rect
Accepted answer
1 votes

After a bit of playing with code, it turns out that the problem is caused by getGObjectAt. It doesn't return a pointer to your paddle even though it's in the specified location. Rather, it returns ...

View answer
placement of structs in code
Accepted answer
1 votes

We do that for functions in order for the compiler to know that there's a function with this signature that exists in our source code so that it doesn't get to a function call before it's defined and ...

View answer
fgetc with sleep unexpected result
Accepted answer
4 votes

The function printf writes to the standard output stream (aka stdout). The stdout usually buffers the data and then flushes it at some point (usually when a newline character is written or when it's ...

View answer
node* root in trie
1 votes

The root of a trie should be an array of node pointers. And the nodes do not store characters. Rather, the index of a node in an array determines which character this node represents. For example, ...

View answer
What stuff that's inside array[-1] or array[n + 1]?
1 votes

In C, there's nothing prevents you from doing such thing as trying to access illegal array indices. Some other languages (e.g., Java) throws an exception at run time if you tried to perform such ...

View answer
unable to use structs to compare with bytes stored in buffer
Accepted answer
0 votes

buffer[0] is a variable of type JPEG which is a struct type as well as pattern1 and pattern2. You can compare the contents of variables of a struct type with ==! Besides, I see this is unnecessary ...

View answer
Memory allocation: recommended practices
Accepted answer
3 votes

I'm not sure you needed to learn about pointers and memory management in order to solve hacker 2. I think you've gone a little bit far. However, I'm gonna try answering your questions. A pointer is ...

View answer
In pset 6 can I rename dictionary.c to test if speller.c compiles?
Accepted answer
0 votes

Yes, you can, but you'll need to replace the occurrence of dictionary.c in the Makefile with mydictionary.c. Or you can simply use a copy of it without changing anything and keep the original file ...

View answer
array of strings
0 votes

You need to determine the maximum length of any string that your program takes as input then to create your array like that char T[n][max]; where n is the total number of strings and max is the ...

View answer
What's the purpose of the 'salt' string? Isn't it contained in the hashed string anyway?
Accepted answer
2 votes

The salt is used to influence the encryption process. If you call crypt twice on the same key passing in different salt each time, you'll get different hashes (results). The salt can be any two ...

View answer
Unable to 'make hello-2'
1 votes

You never linked the CS50 library binary file to your program using the -lcs50 option on compilation!

View answer
Can someone explain me the point of the "int k = atoi((argv[1]);"?
2 votes

You aren't supposed to take input from the user using GetInt. Rather, you are supposed to take input as command-line arguments. As for your question Why do we need to convert the key to int after ...

View answer
How does "make" know how to compile if no "Makefile" is specified?
3 votes

If there's no Makefile in the same directory as the program that you're trying to compile, make uses its default configuration. In the appliance, make uses some environment variables to run the ...

View answer
1
10 11
12
13 14
22