[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 28
Previous thread: >>53831641

What are you working on, /g/?
>>
>>53840598
Please use a roll image next time.
>>
>>53840625
No. Rolls (post number gets) should technically only be on /b/.
>>
well my manga image downloader now scraps the website data automatically for the latest chapter for whatever manga you want
>>
>>53840657
write one for a specific deviantart user
>>
Anyone know why this fails to write any output to the file??

void pack_make_entry(const char* fname, uint32_t fsize)
{
uint8_t buff[32];
uint8_t c;

packed_file = fopen("gdata.dpk", "rb+");
rewind(packed_file);

while((c = fgetc(packed_file)) != 0x00)
{
fseek(packed_file, 32, SEEK_SET);
}

printw("%d ", ftell(packed_file));
memset(buff, 0xFF, 31);
fwrite(buff, sizeof(uint8_t), 32, packed_file);

fclose(packed_file);
}


I'm pretty new to C file IO, and it's seriously fucking me in the arse.
>>
>>53840729
Oh, and excuse the unused variables, they're meant to be there, just unused atm.
>>
>>53840729
>rewind(packed_file);
Unnecessary. The file will already be positioned at the start.
>fseek(packed_file, 32, SEEK_SET);
I don't know what the file is supposed to contain, but do you really want to seek to the 32nd byte each time you see something besides zero? This seems like it could easily cause an infinite loop.
>memset(buff, 0xFF, 31);
>fwrite(buff, sizeof(uint8_t), 32, packed_file);
The last byte of buff is uninitialised. Judging by your code, I assume you want it to be zero, but you have to do that explicitly.
>>
>>53840795
Sorry I should clarify,

I'm going to be writing a struct that's 32-bytes long, hence I'm testing moving 32-bytes when I detect an entry is already taken. As for the second one, that was a typo lol, thanks for pointing it out.
>>
File: qq.png (8 KB, 626x456) Image search: [Google]
qq.png
8 KB, 626x456
>>53840810
fwrite still isn't giving me any output in the file. Is there some reason it would be failing to flush the buffer or something?
>>
>>53840810
>>53840828
So you're trying to write a series of 32 byte structs to a file? Appending it to the end if some structs already exist?
>>
>>53840862
Yeah, similar to how the FAT filesystem creates directory entries. I've got the logic for it all ready, but fwrite's just not actually making the change to the file. buff is just there for a quick 32-byte write test
>>
Anyone know why I keep getting a null pointer exception error? Don't really see the problem.

double answer = 0;
String temp_ecuation = ecuation;
for (int counter = 0; counter != ecuation.length(); counter++)
{
if (ecuation.charAt(counter) == 'x' || ecuation.charAt(counter) == 'X')
{
ecuation = ecuation.substring(0, counter) + x + ecuation.substring(counter + 1);
}
}

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine script_engine = manager.getEngineByName("JavaScript");

try
{
System.out.println(ecuation);
answer = (double)script_engine.eval(ecuation); //This line throws the error
}
catch (ScriptException e) {
e.printStackTrace();
}

ecuation = temp_ecuation;
return answer;
>>
>>53840891
is ecuation being printed correctly?
>>
>>53840891
So
ScriptEngine.eval 
must be returning null. Show us your ecuation you moron
>>
>>53840891
Also it's written equation en ingles, Pedro
>>
File: s.png (1 KB, 396x53) Image search: [Google]
s.png
1 KB, 396x53
>>53840917
Yeah, it all check out.

It started to work now, for some odd reason. I didn't even move anything.
>>
>>53840889
I guess you want to change
fseek(packed_file, 32, SEEK_SET);
to
fseek(packed_file, 31, SEEK_CUR);
or something.
>>
>>53840976
Is it the same input as before?

These things don't throw 'just cause'.
>>
WTF do I do when a person at my new job is turbo feminist and has a MALE TEARS mug? I cant just resign now because that would look bad
>>
Yesterday I asked in a middle of a heated debate how could I make a string variable that's accessible from virtually anywhere in the program, extern static variable, pass it every where as a reference parameter, or somehow use a namespace?
>>
File: LT73HPe.webm (409 KB, 222x400) Image search: [Google]
LT73HPe.webm
409 KB, 222x400
Ask your much beloved programming literate anything.

>>53840625
https://better-dpt-roll.github.io/
https://dpt-roll.github.io/

>>53840729
check ferror()
>>
>>53841051
You could always just use a global variable.
This is exactly what they were made for.
>>
>>53841051
Just make a non-static global variable. You can access it in any compilation unit.
>>
>>53840891
Either
manager.getEngineByName("JavaScript");

must've returned null
what does that method do
>>
File: apple goto bug.png (76 KB, 694x801) Image search: [Google]
apple goto bug.png
76 KB, 694x801
>>53841081
Ask your much more beloved programming illiterate anything
>>
>>53841103
this is why Go forces a coding style, wouldn't have happened with braces
>>
>>53841103
You need brackets around that m8 otherwise goto fail always executes
>>
>>53841117
>>53841122
haha what's go?

those aren't questions
>>
>>53841103
Suggest to me a project doable in the C programming language.
>>
>>53841127
maybe a game or something games are cool
>>
>>53841051
In C++, right? I answered to you that passing the same exact reference was just a way to have a global that doesn't look like a global and in addition bloats your code. As for the namespaces, they exist to avoid name collisions, but don't create a namespace just for one variable. Also what is this variable for?

You didn't acknowledge me yesterday, you broke my heart ::(
>>
>>53841154
I don't feel like it.

>>53841081
Suggest to me a project doable in the C programming language.
>>
>>53841174
Unix terminal multiplexer. You need some buffers, and the manpages of pty and such.
>>
>>53841191
That sounds very difficult. Maybe I'm not cut out to be a programmer.
>>
>>53841174
you the game mastermind, do an algorithm that guesses the colors
or do the synacor challenge
>>
>>53841207
*you know
>>
>>53841157
I went out somewhere and actually lost the signal because my phone is brken. I even posted the question on the move.

The variable is a sort of a log. As the program works, it nicely writes out what it's doing in plain english. It calculates candidate keys for any given set of attributes and functional dependencies. That's why it's important to me that everybody appends to the same output string.

So where do I put that variable, in main.cpp, or do I declare it in all modules?

Also, I did reply, albeit, three or four hours later. Just in case.
>>
Has anyone ever used this fucker right here:
/=

Because I haven't.
>>
>>53841284
For large amounts of code it's great. For a single line? Fucking kill yourself. That said I never knew that // was a C++ style comment and not in C originally.
>>
>>53841300
Wait, what?
I'm talking about
a /= b which is a = a / b
>>
>>53841319
+=, -= and *= are pretty common
>>
>>53841284
>>53841319
I use the compound assignment operators all of the time.
>>
>>53841319
I'm wearing glasses and I still didn't see it was an equals sign and not an asterisk. Just ignore me.
>>
>>53841330
>>53841333
I know about those operators in general, that's why I was referring to that specific division one. I can't recall a situation where that guy would've been handy.
>>
>>53841347
When extracting the digits from an integer, it's very handy.
for (; n > 0; n /= 10) {
emit_digit(n % 10);
}
>>
>>53841278
Ok.

If you copy-paste the declaration, you're doing it wrong. AFAIK it should be

extern std::string log; 
in a header so that all units have it declared;
std::string log("initial contents");
in one particular unit to define (here: construct) it.

Also maybe you want an ostringstream?
>>
>>53841284
I use it instead of != in Haskell and Emacs Lisp. This is not C-like languages general you racist
>>
>>53841411
>using meme languages unironically
>>
If you don't program in a meme language, you are literally cancer and you are destroying programming.
>>
>>53841425
>said the neckbeard that posts anime and "average two ints" hourly in dpt
>>
>>53841438
Good. The more I destroy programming, the less Indians there will be to replace me.
>>
>>53841454
>mad because he doesnt know japanese and cant average two ints
>>
>>53841371
Ill take that, it's good enough. Also, can I chain together the += string operator? Something like
log += "The attribute " += Attr += " was excluded from the key\n";
>>
>>53841460
>japanese
>not a meme
>average two ints
>not a meme
your life a meme
>>
>>53841471
>not liking memes
go home normie
>>
>>53841476
>implying
you wanna imply more
we could shit the thread or dicuss better things like why you hate functional programming so much
>>
>>53841480
because its literally a meme and a waste of time for real projects
>>
File: haskell-fb-industry.png (1 MB, 1128x1080) Image search: [Google]
haskell-fb-industry.png
1 MB, 1128x1080
Attention anon,

come join us in the >>53841487 /fpg/

Remember, Haskell is faster than C - and has the most readable and correct code of any programming language.

We are highly intelligent.

King Regards
>>
>>53841466
((log += "The attribute ") += Attr) += " was excluded from the key\n";

pretty sure it's right associative
>>
>>53841371
Alright, I put the declaration in a header all files include, but for some reason it's throwing what I think are linking errors. It tells me that there are undefined references to alg_log extern variable I made.
>>
How can I round up an int in C (no memes plz)

Say I want to do 740 / 1024, how do I round up to 1?
>>
>>53841675
ceil(740 / 1024)
>>
>>53841675
*unsigned int
>>
>>53841510
People are intent on ruining it, though.

>waaahhh I want <> to do something different for Int in this function
>waaahhh monad transformers are hard, we should use eff even though it's not as good
>waaahhh lens is too complicated
>waaahhh why would you ever need semigroup when you have monoid
>>
>>53841675
(741 + 1023) / 1024
>>
>>53841690
Oh okay, I can use ceil?

Cheers.
>>
>>53841710
Ah fuck, I meant 740, not 741.
>>
>>53841371
Ignore this
>>53841622
I just only realized what you wanted me to do.
>>
>>53841718
If you're okay with abysmal performance.
>>
>>53841724
That's done it, thanks a heap mate.
>>
>>53841737
Is it really poorly implemented?
>>
File: 1425313095730.jpg (62 KB, 300x489) Image search: [Google]
1425313095730.jpg
62 KB, 300x489
>>53841737
Can't wait to hear why and how you would do it better.
>>
>>53841758
It involves unnecessary conversions and floating point arithmetic.

>>53841759
By not using floating point arithmetic.
>>
Microkernel based ARM64 operating system
Named it Gnu Turd
>>
File: 1425315409928.jpg (16 KB, 300x300) Image search: [Google]
1425315409928.jpg
16 KB, 300x300
>>53841777
How would you do it better?
>>
>>53841793
Another anon has already posted the solution. The general form is:

(x + (n - 1)) / n
>>
>>53841495
define real projects
define meme language
>inb4 because I don't like it
>>
>>53841826
How does this even work?
>>
>>53840598
>>53841759
>>53841793
>>>/a/
>>
>>53841873
(automatic 4chan was invented for anime image)
>>
Hey guys, I'm writing my own version of cat in c.
This is the code:
#include <stdlib.h>
#include <stdio.h>

#define ANSI_COLOR_GREEN "\x1b[32m"
#define ANSI_COLOR_RED "\x1b[31m"
#define ANSI_COLOR_RESET "\x1b[0m"

int main(int argc, char **argv){
if(argc < 2){
fprintf(stderr, ANSI_COLOR_RED "Not enough arguments" ANSI_COLOR_RESET"\n");
return -1;
}
int i = 1;
FILE *fp;
while(argv[i] != NULL){
fp = fopen(argv[i], "r+");
if(!fp){
fprintf(stderr, ANSI_COLOR_RED "Failed to open file!" ANSI_COLOR_RESET "\n");
}
printf(ANSI_COLOR_GREEN "%s:" ANSI_COLOR_RESET "\n", argv[i]);
int c;
while((c = getc(fp)) != EOF){
printf("%c", (char)c);
}
if(argv[i+1] != NULL)
printf("\n\n\n");
fclose(fp);
i++;
}
return 0;
}

How can I make it detect if an argument is a folder? For example if I do
mycat *

and the current directory contains a folder, the program segfaults.
>>
File: 1425356982084.jpg (122 KB, 641x1013) Image search: [Google]
1425356982084.jpg
122 KB, 641x1013
>>53841873
I wonder if someone has the breakdown of why the board letters are what they are.
>>
>>53841858
do you wants us to explain how arithmetic works?
>>
>>53841893
>>>/qa/
>>>/a/
>>
>>53841888
in brainfuck
,[.,]

are you even trying c fags
>>
10 results show on google, which I'm not going to hand to you because you're a lazy entitled little worm
>>
File: 1425314541552.jpg (14 KB, 387x355) Image search: [Google]
1425314541552.jpg
14 KB, 387x355
>>53841909
>>
File: pacman.png (4 KB, 625x273) Image search: [Google]
pacman.png
4 KB, 625x273
What's a good heuristic for the pacman food search problem?

The goal state is that pacman eats all the food pellets in the shortest amount of steps possible.

I've tried a heuristic where the predicted cost is equal to the manhattan distance of th farthest pellet.

return max(map(lambda x:manhattanDistance(position, x), pellets))


It works but it's not really very effective.

I've also tried a greedier heuristic where you find the manhattan length of the closest pellet and then from that pellet the closest other pellet until you get to the last pellet (basically a greedy traveling salesman problem algorithm)

This results in a much faster solution but the result isn't always the fastest path available.
>>
>>53841858
Consider a value exactly equal to n. If you add n, you'll have 2n/n and get 2. However, if you add n - 1, you'll be slightly less than 2n and truncation will give you 1.

If you have the value 0, adding n - 1 will give you (n - 1)/n. Resulting in 0.

If you have 1, 1 + n - 1 will give you n/n, resulting in 1.

Sorry, don't know how to format.
>>
>>53841675
740 / 1024 + (bool)(740 % 1024)

or (_Bool) if you didn't
#include <stdbool.h>
>>
>>53841919
>>>/a/
>>
>>53841893
/g/ = Gizyutsu = Technology in weebspeak.
>>
>>53841940
I agree anime fags should gtfo, but don't shit the thread pls, just ignore them
they crave on attention, if u give it to them, u lose
>>
>>53841858
If x is a multiple of n, then we can say x = k.n, and we want k as the result.

Note that here, / is integer division (i.e. rounds down).

Then

(x + (n - 1)) / n = (k.n + (n - 1)) / n
observe that k.n < (k.n + (n - 1)) < (k + 1).n
therefore (x + (n - 1)) / n = k

Otherwise, we have x = k.n + m, where 0 < m < n, and we again want k as the result.

Then

(x + (n - 1)) / n = (k.n + m + (n - 1)) / n = ((k + 1).n + m - 1) / n
observe that 0 <= m - 1 < n
therefore k.n <= (x + (n - 1)) < (k + 1).n
therefore (x + (n - 1)) / n = k
>>
>>53841923
that is traveling salesman problem bro
>>
swallow every drop of my attention you dirty anime obsessed faggots
>>
>>53841961
It's not exactly TSP because the salesman needs to return to the origin, pacman just needs to visit all the pellets.
>>
>>53841957
Why couldn't you just do (x / y) + 1?
>>
>>53841997
It's wrong when x is a multiple of y.
>>
>>53842007
Maths is very smart!
>>
>>53842020
Huh? What do you mean?
>>
>>53841997

(x - 1)/y + 1

Maybe?
>>
>>53841989
The Hamilton Path problem is what you're looking for. For that you also need to visit all vertices but you don't have to return to the origin.
>>
>>53841873
>>53841909
>>53841940
samefag

>>53841893
/g/ used to be gore then society started to take the internet as 'srs business' so it changed to japanese word for technology.

/b/ is random because /a/ was the first board and random needed its own.
>>
Javascript question

I need a function to print out a value that is calculated after a number of forms have been selected

How do you get the function to execute after all the forms are filled?
>>
>>53842044
While we're at it, what's the /r/ on reddit stand for?
>>
>>53842039
now it is wrong if remainder is 1
>>
>>53842039
Yes - that's equivalent to (x + (y - 1)) / y
>>
>>53841888
>How can I make it detect if an argument is a folder?
Assuming POSIX:
#include <stdio.h>
#include <sys/stat.h>

int main(int argc, char *argv[])
{
if (argc != 2)
return 1;

struct stat s;
if (stat(argv[1], &s) == -1) {
perror("");
return 1;
}

if (S_ISDIR(s.st_mode))
puts("is directory");
else
puts("is not directory");
}
>>
>>53842040
It still involves stuff like dynamic programing and ugly matrix calculation.

I guess I'll just stick to my one liner heuristic it's simple and acceptable enough.
>>
>>53842087
Actually no, it's equivalent to (x/y)-y^(-1)+1
>>
>>53842090
Thanks man!
>>
>>53842065
Really?

Round up 8/7 => 2

x = 8
y = 7

(8 - 1) / 7 + 1
7/7 + 1
1 + 1
2

Seems okay to me?
>>
>>53842129
It's correct. The anon who said it was wrong is wrong.
>>
>>53842129
yeah, I was wrong. you subtracted y/y and added +1 to the original algorithm
>>
>>53842087
>>53842110

Just did some quick working:

(x - 1)/y + 1 = z

(x - 1) + y = yz // multiply all by y
(x + y - 1) = yz // collect terms
(x + y - 1) = z // divide all by y

(x + y - 1)/y = z
>>
How much would it take for someone who can spend 2h/day learning on his own to code to be able to make some money out of it?
>>
>>53842040
He's looking for the shortest path, that's not the Hamilton Path problem.
>>
>>53842188
between 0 day and a hundred years
>>
why is this wrong?
#include<iostream>
using namespace std;

int main(){
unsigned int a=0x0001b;
unsigned int b=0x1011b;
b &= a;
cout << "and a&b = " << b;
return 0;
}

prints 27, shouldnt it be 1?
>>
>>53842242
that is not binary bro, it is hexadecimal
>>
>>53842272
1B is 27, mate
>>
>>53842272
result of that operation is 0x1b which is 27.
b is 11 in base 16
>>
Do I put my I/O functions in a separate file? Seems like a good idea to me but maybe that's against a commonly accepted style
>>
>>53842242
>>53842272
lel, he deleted his shame
>>
>>53842280
>>53842281
>>53842300
I just woke up, please, forgive me.
>>
>>53842300
>>53842316
don't worry i saved a picture of it
>>
>>53842242
thats how i wanted it
using namespace std;
int main(){
int a=5,b=1;
cout<<bitset<4>(a&b)<<endl;
return 0;
}
>>
>>53842508
I'm not sure if it's standard or just some gcc thing but you can use binary literals in the form of: 0b101
>>
>>53842554
not standard pig disgusting
>>
>>53842554
yeah i could have written
int a=0b0101,b=0001;

but that doesnt format me the output to binary.
thats what i wanted.
>>
>>53842554
>>53842631
>writing non-standard code like a caveman
you guys should be ashamed
>>
>>53842840
>not using extensions that every major c compiler supports
>muh standards
>>
>>53842840
binary literals are standard C++
>>
>>53842864
Hit the keyboard with rocks while at it, you monkey
>>
>>53842893
>C
>a rock
>not a swiss army knife
>>
>>53842900
I am talking about non-standard code in C. you might as well write in python and call it C because it works in your compiler
>>
>>53842923
C and Python are basically the same language anyway
>>
>>53842923
Every major c compiler supports it.
Who cares if some small obscure compiler doesn't? Those usually don't do your precious standards right or only support an ancient one,anyway.
>>
>>53843024
Writing C is not about the compiler supporting it, it is about the standard supporting it.
>>
>>53843024
>I hate portability and break it with a thing simple as binary literals
>>
>>53843036
Sounds like you're spoiled by programming only for desktops.
I'm already glad when the compiler I'm forced to work with supports ANSI-C well enough.
>>
r8 my fizzbuzz in C

count = 0
while (count < 101):
if (count % 5) == 0 and (count % 3) == 0:
print "FizzBuzz"
count = count +1
elif (count % 3) == 0:
print "Fizz"
count = count + 1
elif (count % 5) == 0:
print "Buzz"
count = count +1
else:
print count
count = count + 1


it is totally C, because

totally_c_compiler fizz.py

compiles it
>>
>>53843070
Nice try pretending. Does the compiler you are forced to work with supports binary literals? I don't think so.

Moreover, if you actually did work with embedded and weird systems you would understand the value of following the standard.
>>
>>53843092
Rate mine
http://pastebin.com/WZdrG4fu
It's totally C because
cat fizzbuzz.c
compiles and executes it.
>>
>>53843105
>Does the compiler you are forced to work with supports binary literals?
The point is you work with what you got instead of what you want it to be.
>you would understand the value of following the standard.
Yes, the value of the compiler following the standard, not myself.
And I hate when I'm forced to conform to MISRA or whatever
>>
File: 1455147558063.png (174 KB, 382x568) Image search: [Google]
1455147558063.png
174 KB, 382x568
I'm trying threads and synchronized methods in java.
I start two threads with the same object that contains my method, but when my method executes, the thread that doesn't have the lock pauses with the other thread as well.
I want one thread to continue on with the rest of instructions when the other is executing the method.
How can I do that?
>>
>>53843160
>Yes, the value of the compiler following the standard, not myself.
Yourself too. How many times have you wanted to kill a library creator because they didn't follow the standard so their library would not run on your implementation?
Let me guess, none because you have no idea what you are talking about.
>>
>>53843193
>would not run on your implementation?
Unless, it was specifically bought for the platform in question, that's pretty much business as usual - standard confirming or not
>>
>>53843163
i am not sure what you are trying to achieve, maybe post some of the code?
>>
File: smug_anime_face.png (306 KB, 593x540) Image search: [Google]
smug_anime_face.png
306 KB, 593x540
>"The similarity between the operating systems disappears when running in 64-bit mode because the function calling conventions are different. 64-bit Windows allows only four function parameters to be transferred in registers, whereas 64-bit Linux, BSD and Mac allow up to fourteen parameters to be transferred in registers (6 integer and 8 floating point). There are also other details that make function calling more efficient in 64-bit Linux than in 64-bit Windows ... An application with many function calls may run slightly faster in 64-bit Linux than in 64-bit Windows."

Why are people still developing on Windows?
>>
>>53843330
https://ghostbin.com/paste/dd3bm

Okay, I think it's pretty self explanatory.
My issue with this code is that the code doesn't continue running on the thread that is not accessing the eat method of Food.
>>
>>53843371
>using more than 4 parameters
>excessive function calls
faggot detected
>>
>>53843371
This is wrong. You can use any calling conventions you want in any system you want. This is just for the "standard abi" (if such thing exists) for the system.
>>
File: sour_grapes.jpg (14 KB, 300x250) Image search: [Google]
sour_grapes.jpg
14 KB, 300x250
>>53843377
>>
>>53843373
because you synced eat() on food? Only one thread can use eat() on same food. What do you think synchronized do?
>>
>>53843410
That's how I understood it as well, but it's telling me that the other thread should be able to run as well?
Like while the rabbit is eating, the turtle can still keep moving during the race.
>>
File: 1458846260431.png (496 KB, 945x1260) Image search: [Google]
1458846260431.png
496 KB, 945x1260
How do you average two integers in Rust?
>>
>>53843440
very carefully
>>
>>53843426
Not if it is hungry and waiting on the rabbit to hrab the food. If two threads attempt to run the method simultaneously, one of them will block, not go o,n because that would be a failure within the sequence of methods call that you write. Do you understand? Show code.
>>
>>53843469
*grab
*on,
*wrote

Sorry: phone
>>
>>53843426
>>53843426
the entire thing is a bit odd desu, why would food be a thread? wouldnt the animal being a thread have more meaning? if you are simulating a race then the animals should be running not the food and if you do insist on keeping the food as a thread then why doesnt the food have a run method?
>>
File: 1450990659352.jpg (122 KB, 725x635) Image search: [Google]
1450990659352.jpg
122 KB, 725x635
>>53843469
Ohhhhh okay.
Nevermind I'm retarded. It says that the turtle should wait for the rabbit to eat so the advantage is reduced.
You are right.
>>
>>53843504
Yes, the animals are the threads. Food.eat() is the synchronized method.
>>
>>53843536
then why does the link you posted contain

public class Food extends Thread
>>
>synchronized as a function specifier
>Object type has mutex functionality
it is like giving a kid matches, what was java designers thinking?
>>
>>53843546
It's just something I was trying that I forgot to remove. I started to think at some moment that maybe it needs to be a thread as well. I removed the run() method I made, but I forgot the extends thread.
>>
>>53843546
he is a java programmer, what do you expect. he probably copy/pasted code from a threading tutorial until it compiled then come here to ask why output is not what he expected
>>
File: 1451020703522.png (139 KB, 308x765) Image search: [Google]
1451020703522.png
139 KB, 308x765
>>53843566
That's not even true, don't bully!
>>
I'm reading my first programming book.
>>
>>53843624
Use the 6th edition, it also talks about ISO C11

https://kat.cr/c-primer-plus-6th-edition-pdf-t8437775.html
>>
>>53843624
>>53843658
Is this a good start for a complete beginner?
>>
>>53843658
I have the 6th edition PDF, but I enjoy having the physical book in my hands more, I found the 3rd edition, in amazing condition at my local goodwill for $3.
>>53843682
I find it a very good ease into learning how to program so far, its got more padding than most C books as far as I can tell, being that its like, twice the length of a lot of recommended books, but I feel like it helps because they describe new things in great detail, and use multiple examples.
>>
>>53843728
I don't mind it being long if it is actually helpful.

I just have this mental barrier where I think I can't learn to code on my own at all.
>>
>>53843780
>I just have this mental barrier where I think I can't learn to code on my own at all.
yeah, we call it stupidity
>>
>>53843682
This is the best first programming book imo
>>
My first time using GitHub, how do I upload .java files into a repository?

I have them on my PC, but can't find out how to actually upload each of them onto each repository.
>>
>>53843830
either use a GUI git client or type something like git add *.java and then commit
>>
>>53843830
Start with git
https://www.git-scm.com/book/en/v2
>>
>>53843830
dude, drag and drop, lmao
>>
>>53843830
>java
it is hopeless
>>
>>53843830
You can't. Linus, in his wisdom, banned ".java" files from the git spec.
>>
>>53843830
If you're using Java, use an IDE like NetBeans or IntelliJ.
They already come with git support.
>>
>>53843890
This
>>
File: robotSquad.gif (914 KB, 893x757) Image search: [Google]
robotSquad.gif
914 KB, 893x757
>>53840598
I'm slowly growing a robot army

Forgive the shit camera angle, I've just been using the unity editor camera until I transplant this code into the rest of my game
>>
>>53843890
Nice try, but I'm not buying it.
>>
>>53844097
What is the other explanation then? You are too stupid to find commit / publish button on your github app? that is ridiculous, no one is that stupid.
>>
>>53844089
>unity
this is a programming thread
>>
>>53844135
>implying you can't program whatever the fuck you want and then use unity as a rendering engine
>implying I haven't written a 3d engine in directx/C++
>implying I haven't written a 3d engine in opengl/C++
>>
>>53844132
Also, not that anon that asked how to commit to git, I know how to commit to git. Haven't used git in 3 years or so, which is why I replied to that post
>>
>>53844135

Unity support c++ plugins so you can pipe whatever want into the engine.
>>
>>53843006
just shut up already if you're caolan you're breaking multiple rules and what you're doing is morally reprehensible and you could potentially piss off complete psychopaths on here. no one here has €7000 to spend on such a worthless not-even-funny gag anyway.
>>
>>53844164
>3d engine in direct3d/opengl
wow, must be so hard. writing a 3d engine in a library that does... 3d rendering
>>
>>53844201
There's a difference between a library and an engine
>>
>>53844227
>write shitty functions that barely add anything
>muh engine
>>
>>53844201

Not him, but you know fuck all if you think opengl is a rendering engine.
>>
when i call
new QImage(bodyName.c_str());
it only sets the value for the next n objects as the first value retrieved from bodyName.c_str(), as opposed to distinct values -- does anyone have any idea why?

    for (int i = 0; i < totalObjects; i++)
{
name = objectVector.at(i)->getName()+".png";
name.erase(std::remove(name.begin(), name.end(), ' '), name.end()); //remove whitespace from start of file name
QImage *image = new QImage(name.c_str());
QImage small = image->scaled(100, 100,Qt::KeepAspectRatio);
brushVector.insert(brushVector.begin(), new QBrush(small)); //default colour to be overriden
}
>>
>>53844253
>never learn to program
>get angry that someone made a choice you don't like
>shitpost on /g/
>>
>>53843830
create a repo on github
do git clone repourl
put shit into your .gitignore
do git add *.java or whatever
git commit -m "I'm a faggot"
git push
fuck off into >>>/g/sqt/
???
profit
>>
>>53843193
>How many times have you wanted to kill a library creator because they didn't follow the standard so their library would not run on your implementation?
Most non-trivial libraries have to use non-standard stuff because you can't do much with just standard C.
>>
>>53844272
nice projection
>>
>>53843830
vim git.sh
type:
git add . --all
git commit -m "Bug fixes"
git push origin master --force
:wq
>>
>>53844272
everyone and their mothers wrote game engines anon. you are not a special snowflake.
>>
>>53844164
>unity as a rendering engine
fucking disgusting as shit and at least use proper shaders with dithering fucking idiot
>>
>>53844318
nice meme
>>
>>53844319
>>53844341
I'm not claiming to be special, I'm just claiming that that other retard doesn't know what he's talking about. Having tried both opengl and direct3d in c++, I got tired of doing lower level things like that and decided my creative endeavours would be better off if some of those lower level things were done for me. C# is a much nicer language to use.
>>
>>53844318
wow fucking idiot you think way too highly of libraries, do you even know what a library is
>>
>>53844383
literally >>>/vg/agdg
>>
>>53844365
The artifacts you're seeing are because of my gif recorder

Also read the rest of the post where I talk about plopping it in the rest of my game which contains better shaders
>>
File: 36743.gif (855 KB, 500x281) Image search: [Google]
36743.gif
855 KB, 500x281
>>53844383
>opengl
>low level
>>
>>53844201

direct3d is literally just an api into the hardware. A full rendering engine handles the meshes, camera, animations, managing the textures, shaders, automating lighting and a tone of other features.

Using straight direct3d or opengl is fun as a project, but you'd be fucking retarded to go that low level for the majority of applications, unless you literally want to spend a year writing what other people have already done better.

Unity is full game engine as well, is royalty free, and saves you a ton of time. Its not "hard" to write a primitive game engine. But you're an idiot if you think you're going to write something better than Unity or similar by yourself in any reasonable amount of time.
>>
>>53844407
Oh good call. I thought /v/ and /vg/ were just for dank memes
>>
>>53844447
/v/ is
>>
>>53844447
>>53844465
/v/ is also the cancer that is second to /b/
>>
>>53844447
>>53844465
>dank memes on a /v board
>>>/reddit
>>
>>53844465
Yeah, /vg/ is mostly just for circlejerks
>>
>>53844485
/vg/ is aright depending on the general
>>
>>53844430
Very well said
>>
in C, say that I have a dynamically allocated struct containing a 2d array, what's the proper way to free the memory?
>>
>>53844566
free(ptr)
>>
>>53844591
I was wondering if I should also free the array if it's dynamically allocated
>>
test
>>
>>53844610
no
>>
>>53844610

Define a destructor delete[] the array. The delete the struct.
>>
>>53844636
>C
>>
Got my C compiler to compile some crypto programs, and to my surprise, they worked!

Feels pretty great when this piece of spaghetti manages to get some shit done.
>>
>>53844629
ok, did it anyway
>>
>>53844636
>destructor
>C
>>
>>53844740
>>53844651
>not implementing your own vtables and classes in C using function pointers typdefs and structs

lmao do you even program?
>>
>>53844663
>reinventing_the_wheel.png
>>
>>53844759
Are you retarded?
>>
>>53844651
>>53844740

Thought c++ immediately because freeing in c is easy. Just free for every time you malloc.
>>
if C added function overloading you'd be able to just overload free to do something different for user defined structs
>>
>>53844932
you can do that with that new generic macro thing in c11
>>
File: selection_sort.png (31 KB, 526x256) Image search: [Google]
selection_sort.png
31 KB, 526x256
Need some help implementing the selection sort algorithm (instead of bubble sort) into this JavaFX program: http://pastebin.com/HjEjg7m9

Yes, this is my homework:
Write a Java program that animates the selection sort algorithm. Create an array that consists of 20 distinct numbers from 1 to 20 in a random order. The array elements are displayed in a histogram, as shown in Figure 23.20a. Clicking the Step button causes the program to perform an iteration of the outer loop in the algorithm and repaints the histogram for the new array. Color the last bar in the sorted subarray. When the algorithm is finished, display a message to inform the user. Clicking theReset button creates a new random array for a new start.
>>
>>53845195
>http://pastebin.com/HjEjg7
>This page is no longer available. It has either expired, been removed by its creator, or removed by one of the Pastebin staff.
You dummy. Plus what's so complicated about insertion sort?
>>
File: 1299301848710.jpg (6 KB, 183x184) Image search: [Google]
1299301848710.jpg
6 KB, 183x184
>>53844725
what does that even do
>>
Well while working on one of my development servers, I fucked the OS, grub repair failed, well then, reinstallation of the OS it is.
>>
>>53845195
>>53845214
http://pastebin.com/TptQX4FB

Sorting algorithm should be something like:

 
static void selectionSort(double[] list) {
for (int i = list.length - 1; i >= 1; i--) {
double currentMax = list[0];
int currentMaxIndex = 0;

for (int j = 1; j <= i; j++) {
if (currentMax < list[j]) {
currentMax = list[j];
currentMaxIndex = j;
}
}
>>
>>53845269
I know what insertion sort is you dumb fuck
>>
File: 1402701085315.jpg (9 KB, 292x219) Image search: [Google]
1402701085315.jpg
9 KB, 292x219
What is the most complex algorithm?
>>
>>53845489
Fizzbuzz of course.
>>
>>53845489
Go AI
>>
>>53845489
the "highest possible complexity" algorithm
>>
>>53845489
solve any sudoku puzzle in polynomial time
>>
>>53845489
https://en.wikipedia.org/wiki/Risch_algorithm
It's still not implemented completely
>>
>>53845489
an algorithm can be made to be arbitrarily complex
>>
>>53845269
Here's a correct selection sort. Now rewrite it in a step-by-step way and plug it in your program.

    static void sort(double[] arr) {
for (int i = 0; i < arr.length; i++) {
int min = i;
for(int j = i+1; j < arr.length; j++)
if (arr[j] < arr[min])
min = j;
double temp = arr[i];
arr[i] = arr[min];
arr[min] = temp;
}
}
>>
>>53845489
implement an algorithm to find out
>>
>>53845489
PB and J sandwich
>>
>>53845489
life
>>
>>53845617
Thanks.
>>
>>53844389
Read the C standard, especially the first couple sections regarding environmental limits and you'll quickly realize just how limited 'standard, portable C' really is.
Prior to C11 you couldn't even make threadsafe programs without compiler extensions for example.
>>
>>53841044
If he/she is not a problem, you can deal with it. Just look for another job, and after enough time has passed tell your boss you got a better offer.
>>
>>53845866
>What are pthreads
no
Thread replies: 255
Thread images: 28

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
If a post contains illegal content, please click on its [Report] button and follow the instructions.
This is a 4chan archive - all of the content originated from them. If you need information for a Poster - you need to contact them.
This website shows only archived content and is not affiliated with 4chan in any way.
If you like this website please support us by donating with Bitcoin at 1XVgDnu36zCj97gLdeSwHMdiJaBkqhtMK