5

Modulo is working correctly, but you've overlooked something. The idea behind using modulo is this. When you represent letters as numbers between 0 and 25 inclusive, and add a number to shift the letter, it may go beyond 25. You can apply % 26 to wrap back to the 0 to 25 range. But it ONLY works if the letters are represented by numbers in that range. ...


3

The int variable named d is a global variable. Global variables are variables that are declared outside of any functions. They can be accessed from anywhere in the source code file and that's why we don't need the function init to accept an int as an argument — because we can access d directly inside it. Usually we use global variables when we need to ...


3

if you want to "list the functions in a library", you should look at the header file(s) aka .h file(s). if you wanna search for functions in the standard library, you could execute man -f keyword to search for man pages referenced by keyword or man -k keyword to search man page descriptions and names for keyword as a regular expression. ex: man -...


3

The plain and simple truth is: Macros are NOT stored directly in memory.(during program execution and/or compiling) What happens is, that, the values are copied from the macro to where you used the macro during preprocessing. When it comes to the compiler they don't even exist, they've been replaced by the preprocessor before they get that far. That is, ...


3

A function is identified by an entry point (address) inside the executable code. You use a function from different parts of your code. If you use a macro, the object code of that macro is substituted in each section of the code where it is called, so you have multiple copies of the same code instead of just one called by reference.


2

First we've been taught to use (void) when declaring a function and use () when calling, using a function... Apart from that, void foo() means "a function foo taking an unspecified number of arguments of unspecified type", i.e. don't assume anything about the arguments of foo; all parameter checking is turned off. This special meaning is intended to ...


2

The fact() function is a recursive function that takes a pointer to an int as input. However, the internal recursive call, return *a * fact(a - 1); is not passing a valid pointer to an int. It's clear that you want to pass the next smaller integer, but you are actually passing the contents stored at the pointer minus 1, instead of a pointer address. This ...


2

For steps 2-3, the data structure (e.g., the hash table in your case) that's gonna be used to store the words in the dictionary and the array of pointers to variables of that type both should be created/declared as global not local to load(). For step 5, as since you're reading char-by-char, you should stop as you hit a newline character as each word in the ...


2

typedef void (*sighandler_t)(int); defines sighandler_t as a pointer type to a function whose return type is void and takes an int as an argument. the name of a function, just like the name of an array, decays to a pointer to a function. you could use it like that void foo(int x) { // some code } // some code sighandler_t p = foo; // p points to foo ...


2

C, by default, passes parameters to functions by value. That means when the function swap is called, two new variables, x and y are created, and the values of the integers are copied into them. When the function returns, the two variables x and y cease to exist. The original data in my calling function is unchanged. This is covered in Week 2 shorts and the ...


2

Nope, won't hurt a thing. It's just a matter of style, but has no effect on functionality. The common practice though is not to have a space between main and the first parenthesis. If this answers your question, please click on the check to accept. Let's keep up on forum housekeeping. ;-)


1

Based on how you write that, I assume both load_words and __init__ to be methods. As you made load_words a method, you'd have to call it like self.load_words instead of just load_words.


1

Yes, it's wrong. According to the c99 standard, the return type of main is "int" and not writing the return type of a function is bad practice. The compiler will assume it's int, but you should write it anyway. Also, the c standard requires you specify whether or not you're taking any arguments for main. You can write int main () in c++, but you shouldn'...


1

No I don't think this is possible. Each script is for the sprite it was written for.


1

The root of this problem lies in the order of operations. In C, postfix increment (++) binds more tightly than dereference (*). Thus, what the code *coins++; does is not to dereference coins and then increment the stored value; rather, it increments the pointer coins and then dereferences this new pointer. The compiler is complaining of the fact that the ...


1

I tried to isolate some of the codes in modular form and created a file just to check this code. It seem to be the problem. Did I declare the function within the if statement wrongly? #include <stdio.h> #include "jpg.h" #include <cs50.h> bool jpgCheck(BYTE data[], BYTE jpgSig[]); int main(void) { BYTE jpgSig[1] = { 0xff }; BYTE data[1]...


1

Just to be crystal clear: if (data[3] != 0xe0 || data[3] != 0xe0 || data[3] != 0xe1 || data[3] != 0xe2 || data[3] != 0xe3 || data[3] != 0xe4 || data[3] != 0xe5 || data[3] != 0xe6 || data[3] != 0xe7 || data[3] != 0xe8 || data[3] != 0xe8 || data[3] != 0xe9 || data[3] != 0xea || data[3] != 0xeb || data[3] != 0xec || data[3] != 0xed || data[3] != 0xee || data[3]...


1

A real answer is further down Take note to how I formatted your code according to CS50's style guide. Well formatted code is important if you expect others (or even yourself at a later date) to read your code. I also took myself the liberty to rename your variables to something more descriptive, because descriptive variable names is also important. How is ...


1

As taught we can pass a whole "struct" by value to a function but we can't pass an array by value. Why? the short answer is: because structs and arrays are implemented differently in C. longer answer: there is a difference between a struct type and its pointer type. for example, given the struct struct MyStruct {// members}; MyStruct s; // and ...


1

The board[][] array is a global variable. In both functions, the code is creating a shadow array called board[][]. int board[DIM_MAX][DIM_MAX]; By redeclaring the board array in each function, it is creating a local array that takes precedence, hiding the global array. This is not the same array as the global array. Once the function ends, the local ...


1

The difference between where a variable is declared is scope. Strictly for this discussion, consider main to be a function, even though it is a special one. A local variable is a variable declared inside of a function is local to that particular function. It exists only inside the function where it was declared and cannot be directly accessed by any ...


1

No words are loaded because the while loop never executes. The fscanf() call is attempting to store a word in dict_word, but the pointer dict_word was never initialized. It wasn't set to null and it wasn't assigned any memory via malloc, so it contains a garbage address. When the fscanf() call executes, it fails and returns 0. If this answers your question,...


1

Notice the difference between the declaration of abs_path/query in main char abs_path[LimitRequestLine + 1]; char query[LimitRequestLine + 1]; vs. the declaration in parse. bool parse(const char* line, char* abs_path, char* query) In main they are char arrays. In parse they are char*. Both your sample outputs should be expected. Both variables appear ...


1

Good question. There is no requirement to capture a return value. Just because a function returns a value doesn't mean that the calling code needs to do anything with it. For many functions, like printf, it is common to disregard the return value. However, when there are bugs in a program, those return values can become useful in diagnosing and debugging. ...


1

For set_int() function, it's not complicated. You understand it correctly. However, things are confusing for C arrays. Actually, to me, accessing array member via bracket notation is just a syntactic sugar. Please consider the following example. // allocate an array of integer with size of 2 int *dynmem_array = malloc(sizeof(int) * 2) // assign values ...


1

Here are my thoughts on your interesting question. It touches on the broader category of error handling. Any return value != 0, in the main function signals an error. Whatever return (error) value is given is arbitrary? To a large extent the return value is arbitrary. It (usually) only has meaning to the "caller". Recall the discussion of $? (testing ...


1

Nothing in the C standard guarantees how function arguments are read (meaning in which order) or in what order they're going to be stored in memory. In the case in main, the memory address where n was stored is a higher number than the address where array is stored. That's why your loop works. This seems to not be the case when the arguments are passed to ...


1

just because a function has a return values, this doesn't mean that you have to use it. per the man page of printf, the value returned represents the number of characters printed (excluding the null byte used to end strings). What happens to the return values of these functions? if you don't store it in a variable and/or use it, it's just ignored. ...


1

You need to return n; in your function. And btw, a+b is not the product :)


1

The string hasn't been given space on the stack. What is on the stack is a pointer called phrase. In the switch statement, they are setting this pointer to point to one of the string constants (like "Bad Request"). These string constants are stored as part of the executable file when you compile. (If you were to look at the server executable using a hex ...


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