|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
Russian Federation4235 Posts
On March 27 2017 00:45 travis wrote: Oh blitz that's an excellent example, thank you.
Just to make sure I am on the right page here, the poblem is that when we dereference p and w in our print statement, they are both going to print from the same address, which currently holds the result of get_val(100) ?
You won't advance at all in C/C++ before you learn the basics, which includes automatic/manual memory and pointers. What you're doing is that you're leaking a pointer to automatic memory (which is always scoped, in this case, within the function body) outside of it's scope. Dereferencing such a pointer is undefined behavior - your program is allowed to do anything, including really gruesome stuff.
|
Any ETA on the "Soon" new OP?
|
Are there any game devs here?
I'm doing a web dev course but it itches me to start creating a game 2d game in the vein of Super Metroid.
What technologies should I start to learn if my focus is low input latency and 60 FPS / controller support? Game should run on Linux, OSX and Windows.
|
On March 27 2017 17:41 DickMcFanny wrote: Are there any game devs here?
I'm doing a web dev course but it itches me to start creating a game 2d game in the vein of Super Metroid.
What technologies should I start to learn if my focus is low input latency and 60 FPS / controller support? Game should run on Linux, OSX and Windows. All my game Dev friends talk about nowadays is unity, so I'd start with that and see if it suits your needs.
|
On March 27 2017 17:41 DickMcFanny wrote: Are there any game devs here?
I'm doing a web dev course but it itches me to start creating a game 2d game in the vein of Super Metroid.
What technologies should I start to learn if my focus is low input latency and 60 FPS / controller support? Game should run on Linux, OSX and Windows. Not quite yet but I have a job lined up for when I graduate not experienced with it for 2d games but I hear Unity is totally reasonable in terms of 2d performance, and has the bonus of being able to target all those platforms and more. Definitely supports controllers too. You could probably achieve something similar with other engines (Unreal is another popular one) but I have even less experience with them than with Unity lol
|
On March 27 2017 18:11 Acrofales wrote:Show nested quote +On March 27 2017 17:41 DickMcFanny wrote: Are there any game devs here?
I'm doing a web dev course but it itches me to start creating a game 2d game in the vein of Super Metroid.
What technologies should I start to learn if my focus is low input latency and 60 FPS / controller support? Game should run on Linux, OSX and Windows. All my game Dev friends talk about nowadays is unity, so I'd start with that and see if it suits your needs.
I'll start with Unity then, there's a billion tutorials and ebooks about that out there anyway.
|
Hyrule18969 Posts
On March 27 2017 15:22 Wrath wrote: Any ETA on the "Soon" new OP?
Soon
|
|
Ok, need help with a proof, maybe some of you could tell me what you think
Question:
+ Show Spoiler + Let T be defined by:
T_0 = {0, 1, 2, 3, 4, 5, 6} (for all n >= 0)[if x,y,z are in T_n, then x^2+y^2+z^2 are in t_(n+1)]
T = The union from i=0 to infinity of T_i
(so, it's T_0 U T_1 U T_2 etc etc)
Now, prove that for all w in T, w is not congruent to 7 (mod 8) using structural or weak induction
So, this is what I have so far:
+ Show Spoiler + For all w in T_0, w fulfill the following cases
w = 0, w^2 is congruent to 0 mod 8 w = 1, w^2 is congruent to 1 mod 8 w = 2, w^2 is congruent to 4 mod 8 w = 3, w^2 is congruent to 1 mod 8 w = 4, w^2 is congruent to 0 mod 8 w = 5, w^2 is congruent to 1 mod 8 w = 6, w^2 is congruent to 4 mod 8
Therefore for all w in T_1, we have the following cases (all values are mod 8)
0+0+0 = 0 0+0+1 = 1 0+1+1 = 2 1+1+1 = 3 4+0+0 = 4 4+0+1 = 5 4+1+1 = 6
so like.. i think I already have shown what it takes to prove it. But I don't know how to form this into an inductive proof. Particularly weak induction where I need an inductive base, and inductive hypothesis, and inductive step. My base would be T_0 proof, but I don't know where I would go from there. So yeah, any help with that would be awesome
|
Assume it holds for T_n, and use that to prove it holds for T_n+1
|
|
I have a quiz on dynamic memory allocation tomorrow and I am a bit behind so I am reviewing.
+ Show Spoiler + Implement the append function that has the prototype below. The function returns a string that represents the concatenation of all the strings present in an array of strings. For this problem, you can assume the end of the parameter array is marked by NULL. You need to allocate memory for the resulting string. You may not modify the array parameter. char* append(char *data[]);
Is this how you do that? Handwriting, not testing any of these yet.
+ Show Spoiler + char* append(char *data[]) { size = 0; index = 0; char *appendvalue;
while(data != NULL) { size = strlen(data[index]) + size; index++ }
appendvalue = malloc(size + 1)
index = 0; while(data != NULL) { strcat(appendvalue, data[index]); index++ }
return appendvalue; }
ok now please take it easy on me... very little experience in this realm. I have a feeling I am screwing multiple things up. Such as if I am even using strcat right (I get confused about the actual difference between how C treats a character array vs a char pointer. Also i suspect that the better way to do this may to use realloc in my first while loop and I wouldn't need a second while loop?
Or maybe I am just super super off base with all of this and am so far off that a hero can swoop in and save me?
Anyways thanks all for your time.
edit: more
+ Show Spoiler + The following C statement creates an array of 14 characters. char *desc = (char *) malloc(sizeof(char) * 14); Indicate whether the code can be simplified or not. If the code cannot be simplified indicate NO. If it can be simplified rewrite the code below.
change it to malloc(14) ?
last one:
+ Show Spoiler + The following structures are used for these questions. #define MAX_LEN 80 typedef struct { char *title; int duration; } Song; typedef struct { Song* all_songs; /* array of songs */ int number_of_songs; char album_name[MAX_LEN + 1]; } Album;
a. Given two Song structures s1 and s2, are there any problems with assigning one structure to another? Is deep copying taking place during the assignment of these two structures? b. Define a function that initializes a Song using a duration and a string provided. The function will make a copy of the string parameter. c. Define a function that will initialize an Album structure based on an array of Songs provided as parameter. The function will create a dynamically-allocated array of Songs and will initialize each entry with a copy of the corresponding song in the parameter array. Feel free to add to the function any parameters you understand are needed.
+ Show Spoiler +a.) is there a problem in that when everything is copied, the pointers are copied, which could lead to problems, since we can't independently change the songs in one album without changing the songs in the other? b.) Song init_song(int d, char *s) { Song song; strcopy(song.title, s); song.duration = d; return song; }
//eh... this easy?
c.) Album init_album(Song *songs) { Album album; album.album_name = "they didn't say anything about this";
//I don't know how to assign the songs. //I don't even know how to tell when I have hit the last song. I mean I go through them with pointer //incrementation, right? But how do I know when I am past the last song? Does the pointer become //null?
thanks
|
|
Nesserev, first, thank you for the comprehensive review of my code.
Quick question - what is the actual purpose of casting malloc? Isn't it just a chunk of memory?
People seem to be arguing about it here: http://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc
But I don't understand why a chunk of memory needs a type anyways! Isn't it getting it's type by being assigned to something?
edit: I guess the malloc function returns a pointer. so me calling it "just a chunk of memory" is clearly incorrect.
|
Casting the return value of malloc is a bad idea. void* will be implicitly converted into any other pointer type, so don’t cast it.
|
|
While I have got you guys, could you take a look at the 4th spoiler? I feel more confident since I was in the ballpark on the first one, but I am really unsure what to do for this question.
|
On March 29 2017 06:58 Biolunar wrote: Casting the return value of malloc is a bad idea. void* will be implicitly converted into any other pointer type, so don’t cast it.
I've always seen casting malloc as part of the coding standard. While pointless it is a sanity check.
|
|
On March 29 2017 07:28 Blitzkrieg0 wrote:Show nested quote +On March 29 2017 06:58 Biolunar wrote: Casting the return value of malloc is a bad idea. void* will be implicitly converted into any other pointer type, so don’t cast it. I've always seen casting malloc as part of the coding standard. While pointless it is a sanity check.
It's also recommended in older C standards.
|
|
|
|