/dpt/ - Daily Programming Thread

Old thread: What are you working on, Jow Forums?

Attached: 1487413306014.png (611x720, 383K)

Other urls found in this thread:

wiki.sei.cmu.edu/confluence/display/c/MEM02-C. Immediately cast the result of a memory allocation function call into a pointer to the allocated type
cs.cmu.edu/~15122/schedule.shtml
cs.cmu.edu/~ckaestne/15214/s2017/index.html#schedule
cs.cmu.edu/~ckaestne/15214/s2017/slides/20170124-design-for-change-2.pdf
wiki.sei.cmu.edu/confluence/display/c/MEM10-C. Define and use a pointer validation function?src=contextnavpagetreemode
pastebin.com/rqSgL9P0
101.lv/learn/C /
twitter.com/NSFWRedditGif

a top down shooter i guess?
are stupid questions allowed in this thread?
people on stackoverflow are wankers

Attached: Capture.png (1366x641, 59K)

AS3 is the best language to have ever been created and you're all troglodytes if you use anything else.

A Daily Programming Thread without any autistic political pictures! Great job OP!

As a side note: does OP actually interact with the thread?

>are stupid questions allowed in this thread?
Stupid programming questions should go in dpt, stupid not-programming questions should go in sqt

taking a break at SICP, p282.
Realy got to let the model with which they simulate circuits sink in.

Attached: 1525005500406.png (478x483, 155K)

adgajhwdg

Why is this thing not restarting when there's a draw?
public static void main(String[] args) {
Game game = new Game();
game.play();
}
public void play(){
while(true){
displayBoard();
if(getMove()){
displayBoard();
if(Turn)
System.out.println("win" + player1);
else
System.out.println("win " + player2);
}else if(boardFull()){
displayBoard();
System.out.println(" ");
System.out.println("draw");
Game game = new Game();
}else {
Turn = !Turn;
}
}

I have this thing that parses stuff:
struct jValue *ParseValue(wchar_t *string) {
struct jValue *value = malloc(sizeof(struct jValue));
if(!value) {
fprintf(stderr, "Error: Failed to allocate a jValue!\n");
exit(-1);
}

if (wcscmp(string, L"null")) {
value = NULL;
} else if(wcscmp(string, L"true")) {
value->type = jTBoolean;
value->boolean = true;
} else if(wcscmp(string, L"false")) {
value->type = jTBoolean;
value->boolean = false;
} else if(string[0] == '\"') {
value->type = jTString;
// Memcpy so that caller can safely free reference to argument
// This way, there's no need for reference counting.
size_t len = wcslen(string);
value->string = malloc(len * sizeof(wchar_t));
if(!value->string) {
fprintf(stderr, "Error: Failed to allocate a jString!\n");
exit(-1);
}
memcpy(value->string, string, len * sizeof(wchar_t));
}

return value;
}

In main I try and use it:
struct jValue *v = ParseValue(L"\"\"");
wprintf(L"%lc\n", v->string);

but the wprintf causes a segfault. I used gdb to see what the problem was and gdb gave me pic related. Why is the argument I pass in code different than the one that ends up being passed in the executable and that gdb sees?

Attached: Screenshot from 2018-07-14 16-56-14.png (947x486, 115K)

wiki.sei.cmu.edu/confluence/display/c/MEM02-C. Immediately cast the result of a memory allocation function call into a pointer to the allocated type
CERT C recommends casting return value of malloc
implicitfags btfo

SICP is a Jewish meme, read TAOCP.

I'm gonna make a simple blacklist engine that can recognize files by SHA hashes.

Right now I'm familiarizing with Qt and I'm gonna use that to write it. I made a simple command line parser with it, then I'm gonna look into SQLite and hashing.

Attached: Qt_logo_2016.svg.png (1200x880, 33K)

There are still very good utility libraries. There are several neat string libraries, for instance.

>writing the type out three times
C is garbage

>Nearly every C-fag I know carries around from project to project same set of home grown utility functions for very basic tasks.

Can confirm. It's basically a ritual for every C programmer to make their own memory/string functions. Hell, I love my functions so much I switched to freestanding C and wrote my own custom standard library.

>qt
>not libui

Because you didn't write a proper specification.

Read what contracts are
cs.cmu.edu/~15122/schedule.shtml

Now read this
cs.cmu.edu/~ckaestne/15214/s2017/index.html#schedule specifically the part about textual specifications/contracts: cs.cmu.edu/~ckaestne/15214/s2017/slides/20170124-design-for-change-2.pdf

Now rewrite that entire main() to satisfy the exact specification, restart should probably be it's own subroutine, in fact the entire code should be minimized: with 90% of that stuff moved to other reusable functions.

This is nothing but cargo cult.

I use Qt because the place I want to work at in the future uses Qt and I want to learn it

Is the thing about Haskell using 60 or so GB to sort an array real or just a nice meme pasta?

user i am a newbie, can you tell me how did you build that grid?

>unfortunately I can't be on campus right now; one of the TAs - "Inf" is having some problems and we're trying to lay low; he's gonna have to turn himself in to do a bit [...]
>one black TA
>has to turn himself in
>prof and other TAs "are laying low" off campus because of it
the fuck, what's wrong with american universities

Attached: huhh.png (1014x836, 487K)

>asking to ask
I hate you fags

Don't forget to take your meds

I'm trying to get the kinect sdk to work on Windows 10. After a while I decided to take the day off and work on my light saber instead, which at least is more rewarding.

>want a book
>book is in HTML form, spread around many pages
>start digging in the site's html, figuring out how to use bs4 and requests, how to circumvent the content warning page (used cookies)

>finally manage to get a list of all the URLs I need, time to downl-
>last url is literally called "download"
>in it there is a link to a pdf version of the book

Attached: 1445178997001.png (1259x947, 2.89M)

>kinect
what is this, 2010?

>laying low
The fuck? Have they been involved too? Why air that online?

It would have been easier back then. It didn't age well, but it's the only way I found to get skeleton tracking under 150€. I bought v1 for 8€ and I'll probably upgrade to v2 for 25€.

they are obviously protecting the TA from injustice, police brutality, racial profiling, etc

Learning c# for a class. Is it worth it to keep learning more about c# after the class or should I move on to another language?

>Is it worth it to keep learning more about c# after the class
If you want a job in programming, at least looking at the job market where I am.

If I include in a Hello World program and compile it with g++ on Windows, MinGW links the executable against its own dlls instead of Windows' standard dlls.

As I understand, MinGW should link against MS's own dlls whenever possible. Why does it links against its own dlls for something as trivial as iostream?

Can't believe a dumb Hello World program has to depend on MinGW.

time to free up 20GB and install Visual Studio

You should be able to solve this

Attached: arrows.png (800x800, 105K)

That's the only option on Windows, is it?

|
v

>absolute state of american universities

learn to program Harjeet Dhaliwal

How is VS this big, seriously?

reasoning?

Pelles C is the White man's choice

Are you honestly so stupid you can't recognize sublime comedy? It's a running inside joke that Andy Pavlo is a G running some kind of criminal enterprise in every lecture.

This is honestly why those courses have a sarcastic 'trigger warning' for people like you too dumb in life to recognize comedy

He may have been talking about the maximal MinGW install. In my case MinGW takes 250 MB.

FUCK

Attached: tumblr_inline_ojqu08KXS41ty2t28_1280.png (1160x694, 1.27M)

(The 3 other rows have all of the 4 directions
Down is what's missing for the incomplete row)

That was my reasoning but I just looked again and it doesn't seem to be that way.

Are you honestly so stupid you can't recognize sublime comedy?

Down maybe? The first two rows of rotations were

180 90 90
90 90 90

Then the bottom rows is:

-90 -90 -90

If we assume -180 in the missing cell then the whole row looks like this

-180 -90 -90

These are just random arrows, aren't they?

No, its from facebook puzzle page and i cant find a solution I believe in. But there is a solution.

Is the most reasonable thing ive seen so far.

It wasn't me.

Sell me lockless computing

Why so many integer constants are written in hexadecimal in the native packages of many languages?
Is the assignment of hexadecimals faster?

Assignment is the same, but with hexadecimal you can easily tell which bits will be set.

And when dealing with memory mapped IO pins, hex is used because its the literal memory address of the pin in question.

If I wanted to use object pascal should I pirate a copy of RAD Studio 10.1 Berlin or Lazarus? Also is Delphi compatible with Free Pascal like will my code be similar on both and will they have similar speed during execution?

>Object Pascal
>Delphi
>2018
Please no

You can also just try debugging. Set a breakpoint at where the new game is called, call it with a draw as a test, and see what happens. Step through the code. My guess is change 'Game game = new' to 'Game newgame = new Game()' instead of reusing the same variable from outside that play() function

Why does javac complain that variable `male` might not have been initialized?

import java.util.Scanner;

public class atwo
{

public static void main(String[] args)
{
var stdin = new Scanner(System.in);
System.out.print("Enter your First name:\t");
stdin.nextLine(); // saving name is pointless because it's not useful later
System.out.print("Enter your second name:\t");
stdin.nextLine();

Boolean male;
double height, weight;

System.out.print("Enter your height:\t");
height = stdin.nextDouble();

System.out.print("Enter your weight:\t");
weight = stdin.nextDouble();

Boolean loop = true;
do {
System.out.print("Enter your gender:[m/f]\t");
switch (stdin.next().charAt(0))
{
case 'M':
case 'm':
male = true;
loop = false;
break;
case 'F':
case 'f':
male = false;
loop = false;
break;
default:
System.out.println("Could not parse gender, try again.");
}
} while (loop);

var bmi = weight / (height*height);
System.out.printf("Your BMI is %f You are %s\n", bmi,
bmi >= 40
? "Morbidly obese"
: bmi >= 30
? "Obese"
: bmi >= 25
? "Overweight"
: male
? bmi >= 20
? "Underweight"
: "Acceptable"
: bmi >= 19
? "Underweight"
: "Acceptable"
);
}
}

Working on some Crystal libraries

>"Can I get a PDF of this book?
>"No, our contract with MIT Press forbids distribution of too easily copied electronic formats of the book."
>use my newly acquired knowledge to download all of the book anyway
devilish

Attached: 1509371269842.jpg (750x572, 48K)

The default value for a Boolean (object) is null.
The default value for a boolean (primitive) is false.

Because the initialization is inside switch cases and the compiler can't possibly know that the variable will be used only after you get the case that initializes male

Attached: 1349909715063.jpg (566x480, 65K)

The initialization isn't inside of a switch case. It's not initialized at all. The issue is that he's declaring a Boolean (and not a boolean), and not initializing it.

The remedy would be to either turn it in to a boolean (instead of a Boolean), or to initialize it as something. As it stands, male is uninitialized and is considered null.

God you're fucking stupid, aren't you?

It's initialized in the switch case based on what the user gives as input.

To me, initialization means giving a first value to a variable.
If it means anything else to you then you're wrong.

>It's initialized in the switch case
That's assignment, not initialization. Not him btw

assert girl(male)

You're talking about assignment. The Boolean object in this case is given the default initial value of null. You could argue that it is considered initialization, but you'd be arguing semantics and that'd be taking away from the issue at hand. user needs to either initialize his Boolean, or turn it into a boolean.

any resources to for an intermediate C programmer to learn C++? mostly looking into using C++ as an extension rather than purely writing C++.

wiki.sei.cmu.edu/confluence/display/c/MEM10-C. Define and use a pointer validation function?src=contextnavpagetreemode
Why do people take CERT C seriously again?

don't, become an expert C programmer instead

Please critique my assignment uwu
pastebin.com/rqSgL9P0

Attached: 1530145000183.png (740x1913, 522K)

>Chaining ternary operations together
Please no.

> boolean male

Attached: 1501767811017.png (600x376, 226K)

>literally assuming gender

I wouldn't but it seems javac isn't smart enough to see that male state is assigned later

u w u

>Boolean male
it's not the 19th century anymore. use a double shitlord

this

I used this 101.lv/learn/C / when I went from C to C++.
It's probably a bit outdated by now though, and you won't learn modern C++.

b-but the widely used toolkits, multi-threading, the Qt library!
GTK seems to be changing its function naming like crazy, that makes it an unreliable toolkit :(

Explain this.
var hurdles = Map.of(
"quiz", 10, "mid-semester", 20, "project", 40, "finals", 30);

double score = 0;
var stdin = new Scanner(System.in);
// for (var hurdle : hurdles.entrySet()) {
// // no orderly iteration because it was not a requirement
// System.out.printf("Enter your %s score:\t", hurdle.getKey());
// score += stdin.nextDouble() * hurdles.get(hurdle.getKey()) / 100;
// }
// works!


hurdles.forEach((hurdle, weight) -> {
System.out.printf("Enter your %s score:\t", hurdle);
score += stdin.nextDouble() * hurdles.get(hurdle) / 100;
});
// aone.java:20: error: local variables referenced from a lambda expression must
be final or effectively final
score += stdin.nextDouble() * hurdles.get(hurdle) / 100;
^
1 error

Sorry I only "learned" Java last night.

>var
fuck outta my face

>Car car = new Car("Car");

Attached: 30688277.jpg (720x720, 34K)

Is there a way to configure Hyper js terminal to give color syntax for C programming?

Are you a script writer for NCIS?

Boost is trash.
C has multi-threading too, but async is better for most purposes.
Qt and GTK are both bad, platform-dependent trash. Use libui or nuklear instead.

>Exception is bad
>Proceed to use setjmp
The state of c.ucks

wut?
I just like my code to look nice and it would be more comfortable to do everything inside Hyper instead of VS Code

you realize qt provides much more than just ui right

Help me improve my code, /dpt/. Look at this unholy mess. The code does what I want it to, but it doesn't look elegant.

std::string Matrix::toString()
{
std::ostringstream oss;

//First line
size_t i = 0, j = 0;
oss

not that guy, but what the hell is qt? i can't wrap my head around it

Tell us what it does first ditt stolpskott

std::string Matrix::toString(){
std::ostringstream oss;

//First line
size_t i = 0, j = 0;
oss

>unholy mess
it's C++

>nuklear
this looks promising! thank you so much!

Attached: ae06f0ca-a0c6-11e5-819d-5610b25f6ef4.gif (800x533, 3.97M)

Yes, but nothing of value.
Generalize it all into one loop that puts in newlines and braces conditionally. Padding is done by setting x = 0 on newline, then doing
while (x++ < 4)
oss

std::string Matrix::toString()
{
std::ostringstream oss;

oss

Have you guys done any evolution sims? Is it a good way to get into AI coding?

I'm not sure having a bunch of if if actually any more elegant. Also what do you mean by your code? All it does is insert 4 spaces, in an unnecesaryly complikcated way.

Doesn't get the formating right. No indentation, and the last ']' ends up on a new line all by itself.

this is the canonical solution btw