You went down the rabbit hole with this pset. You chose the wrong path at the fork on the road. Just think for a minute how mush you will have to change, if instead of 5 letters which is the current maximum length of passwords, it was changed to 6!
You should definitely rethink your solution (if you have finished all psets I think you have what it takes now)...
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 basically a variable that stores an address of a location in memory. Pretty much every type has its own pointer type. For example, char has char *, int has int *,...
It may not look clean, but it is. Complex doesn't necessarily mean inelegant. Think about this. Both signatures have the same first 3 bytes, and there are two choices for the last byte. You've tested for exactly that.
As efficiency goes, as soon as one of the first 3 bytes doesn't match, the whole test is false so the code stops looking. If it gets to ...
Consider removing the typecasting, because it is essentially redundant. A char is a one-byte integer; the system does it's own internal "casting". Perhaps rewatch the caesar walkthrough. Starting around 4:45 Zamyla discusses ascii math.
Change (int) alphabet to ((int) alphabet).
The parentheses won't change the meaning (as typecast has higher precedence than binary minus operator), but they silence style50 (and are my preferred style for typecasts).
This output is indeed not very helpful. I guess they create a "properly formatted" version of the script and apply a generic diff tool (you can learn more about those later in the course, in the "similarities/more" problem). Easy solutions coming to my mind would cause serious limitations.
It's usually considered good style to add a single space on both ...
This is quite simple to do, as all you really are doing through the line is test whether or not the the letter is even a letter, which can simply be checked by C's own function isalpha(text[i]).
For more, simply execute "man isalpha" at the terminal and read the manual page for the function, so, now, you long line if ((text[i] >= 'a' && text[i] <=...
Interesting question. In my opinion, your code is correctly styled.
Both of the other answers provide a solution to the problem. But, the real problem is style5050 itself. Again, in my opinion, this is the rare case where style50 doesn't know how to correctly handle this.
If you put parentheses around the cast and the var, as blauef suggested, it quiets ...
Well, one way is to use the functions isupper() and islower()
if (islower(text[i]) || isupper(text[i]))
alternatively, even shorter is using the isalpha() function
which returns true if the char is alphabetic (ie, upper or lower).
You'll need to #include <ctype.h> to use those functions.
Hope that helps!
I think that your style is perfect.
In general its good practice to use sensible variable names where possible. This eliminates the need for comments at each instruction or decision.
for the sake of an example:
for a simple swap function in a sorting array you may write:
int t = a[i];
a[i] = a[i+1];
a[i+1] = t;
Which may need some comments for longer ...
There are no hard and fast rules on how to split a long test condition. It's mostly about doing what makes sense and what makes it easiest to read. For instance, putting one test condition per line when there are many of them is a good idea. I would never put a line split in the middle of a test condition. Also, indenting the split is definitely a good ...
First, you search the documentation of setFont(). I found this:
void setFont(GLabel label, string font);
Changes the font used to display the GLabel as specified by the string font, which has the following format:
where both style and size are optional. If any of these elements are missing or specified as an asterisk, the ...
I made something simple but I think you can tinker further on your own:
<link rel="stylesheet" type="text/css" href="style.css">
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 say "OK. I don't know what that is!".
For structs, on the other hand, if you're trying to declare a variable of a struct type before it's defined, that'll be ...
You could, actually, and it should work. Try this out:
struct date MyBirthday;
MyBirthday.day = 36;
MyBirthday.month = 15;
MyBirthday.year = 2165;
printf("%s: %d/%d/%d\n", "My birth date was",