[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: 31
File: Homura_DPT_rust.jpg (128 KB, 563x712) Image search: [Google]
Homura_DPT_rust.jpg
128 KB, 563x712
Old Thread: >>47040809

What are you working on /g/?
>>
>>47053693

Also:

Thank you for using an anime image.
>>
Tinkering with Visual C++. In general, will I see performance benefits by offloading some tasks to a C++ library from within C#?
>>
>>47054186
>weeb image
>hide thread instandly
>>
http://www.nand2tetris.org/10.php

Working on implementing a compiler in C++ for laffs. Anyone worked on this project before?
>>
Which programming books had the most impact on your ability as a developer, /dpg/?
>>
from other thread

>>47054472
>trying to learn some git.
>I cant for the life of me figure out how to create a repo on a remote from the command line. I'm using github... not a private repo.
>everything I see shows how to add a remote, and work from it, but not how to actually create the repo.
>anyone have tips or guides
>>
File: Untitled.png (5 KB, 432x360) Image search: [Google]
Untitled.png
5 KB, 432x360
After an overly long amount of time, BEHOLD, a nav-bar that only sort of sucks.
>>
>>47054186
You had to do it, didn't you? You HAD to put one of your mangimu images as the OP.
>>
>>47054435
javascript the good parts

obviously the javscript bible, some interesting functional takes on javascript. it's probably overstated because everyone that touches node or client webdev has read it, but its a legitimately important read.
>>
>>47054498
>git clone
>>
>>47054513
GNU/NEETs got all the free time in the world, of course they'll be lurking waiting to make a new thread to show those filthy normies
>>
>>47054513
Why is that a big deal to you?
>>
Hey guys
in C, how the heck do you turn a single line from a text file into a single string? The way I'm going about it seems extremely convoluted and unnecessary for such a simple task
>>
>>47054615
> The way I'm going about it seems extremely convoluted and unnecessary for such a simple task
C
>>
>>47054592
I'm trying to do the opposite, I have a local repo, im trying to create the github repo from my local repo using the command line...

possible?
>>
>>47054615
char * buffer = 0;
long length;
FILE * f = fopen (filename, "rb");

if (f)
{
fseek (f, 0, SEEK_END);
length = ftell (f);
fseek (f, 0, SEEK_SET);
buffer = malloc (length);
if (buffer)
{
fread (buffer, 1, length, f);
}
fclose (f);
}

if (buffer)
{
// start to process your data / extract strings here...
}


Welcome to C, where simple tasks are convoluted.
>>
>>47054615
you may be able to find another library to do this for you, but std::string is just a char array. and arrays in C are just blocks of memory.

There is no built in abstraction for this, so if you dont want to find an appropriate library you are going to be doing funky memory management operations.

if you are doing a lot of string operations save yourself the headache and use a higer level language. Java would probably be a happy compromise.
>>
File: box.png (806 B, 206x136) Image search: [Google]
box.png
806 B, 206x136
>tfw thought I was getting dumb and turning into >>47051634
>tfw I can still do dumb programming exercises

Maybe I'll get hired after all, then I can never do that stupid shit ever again.

So that was the extent of my daily programming.
>>
>>47054700
>java
I'm a faggot C-elitist, no thanks.
I know there aren't "strings," I know what they are, etc.
I just needed to know if there was a simpler way to accomplish the task, not be lectured to use a different language as if I just started learning C.
>>
File: sakura flipping niggers off.jpg (180 KB, 1440x1080) Image search: [Google]
sakura flipping niggers off.jpg
180 KB, 1440x1080
>>47054513
Anime is the norm not the exception here faggot.
>>
>>47054741
CS Undergrad pls go and stay go.
>>
>>47054741
>I know there aren't "strings," I know what they are, etc.
well then you didnt need to ask the question as if you didnt.
>>
>>47054615
>2015
>not using C++
>>
>>47054498

git init
>>
>>47054641
Create the repo using github's web interface, then point your local repo at the remote one.
>>
>>47054754
>le cs major meme
>doesn't use java
ok
>>47054757
I asked to see if there was a simpler way, not because I didn't know a way.
>>
>>47054774
well, that was my fallback...

I just thought there would be a way to do it from the command line.

maybe not...
>>
>>47054615
gets()

but you should roll your own getline() function that uses dynamic-allocation, because buffer overflows.
>>
>>47054793
>I asked to see if there was a simpler way, not because I didn't know a way.
>Simple memory management in C
tl;dr - nope
>>
>>47054186
I often define these two functions in stuff I'm working on.
 char* get_file_data(FILE* file) {
char* fdata = NULL;

if(file) {
size_t fsz; /* File size */

/* Get file size */
fsz = get_file_size(file);
/* Store contents of file in fdata */
fdata = (char*) malloc(fsz + 1); //+1 for trailing '\0'
fread(fdata, fsz, 1, file);
return fdata;
}
else {
puts_err("@func get_file_data\nCould not get file data");
return NULL;
}
}
size_t get_file_size(FILE* file) {
size_t fsz;

if(file) {
fseek(file, 0, SEEK_END);
fsz = ftell(file);
rewind(file);
return fsz;
} else {
puts_err("@func get_file_size\nCould not get file size");
return 0;
}
}
>>
>building web app
>making solid progress, feeling good about it
>check out producthunt to see what other shit is being made these days
>three days ago my exact idea was posted
>#1 on producthunt

Fuck. Everything is shit.
>>
>>47054794
>I just thought there would be a way to do it from the command line
Sure there is. use git remote add
>>
>>47054794
>>47054833
Oh wait, you want to locally CREATE the repo?
That'd be git init, and then add files with git add, and then use get remote add to add github as a remote
>>
>>47054615
strtok()
After you get your file data do this to split it line by line.
char* fstrs[flines];  int fstrs_i = 0;
char* tok = strtok(fdata, "\n");
strdup(fstrs + fstrs_i++, tok);
while(tok != NULL) {
strtok(NULL, "\n");
strdup(fstrs + fstrs_i++, tok);
}
>>
>>47054833
again, that's adding an alias for an existing remote repo, not creating one
>>47054847
right, but that doesnt create the remote repo, it just links it
>>
>>47054753
>Anime
>/g/
>Normal

Pick only one.
>>
>>47054753
I would say more people here use linux than know the dude in your pic.
>>
>>47054874
I'm not entirely sure what you want to do here if not that.
>>
>>47054874
Creating a github repo from the command line can't be done using raw git, because gh only lets you interact with their servers through their API. They do provide a wrapper, but keep in mind that using it means that you're privileging code on github over code hosted somplace else, which has some nasty ethical implications IMO:
https://github.com/github/hub

If you wanted to set up a remote-only repo, like github's, on one of your own machines, you'd just ssh in and
git init --bare
. The only difference between this kind of repo and the kind that you make on your machine is that git won't bother to check out a working copy of you code, it just holds the history and give you a place to push and pull from.
>>
>>47054987
I have github account "Anon", and local git repo "myGitRepo"

I want to create

https://github.com/Anon/myGitRepo.git

from the command line

>>47055011
okay, that's what I'm gathering.
I looked into creating a repo on my server, but this is going to be a demo server running live code in a couple months and I dont want to risk source being compromised in event of a break in. or add a larger burden to deployment if / when I need to scale out.

So i'll live with the website for now, and work from that when I have to.
>>
File: Grasshopper Elite Headscratch.jpg (49 KB, 436x467) Image search: [Google]
Grasshopper Elite Headscratch.jpg
49 KB, 436x467
https://www.youtube.com/watch?feature=player_detailpage&v=KE5lF4RjJzQ
>people in this thread will honestly try to tell me that they don't enjoy this
Pssh yeah right.
>>
>>47055047
Use github's "hub" utility and make it with hub create

https://github.com/github/hub
>>
>>47054198
>>>47053693
curious about this too.
>>
Any reason why my child destructor is getting called first then my parent destructor. C++ btw
>>
>>47054435
algorithms and data structures
>>
>>47055103
There are a couple of tutorials but they all seem to be incredibly convoluted. I'm positive there is a way to do it that is as simple as using column as the x value, new line as the z value and the colour as the y value but I'm too stupid to figure it out.
>>
I've got a queue, which can add and remove items in constant time.

I need a way to remove an arbitrary item from the queue in constant time as well.

Is there a data structure that can do that?
>>
>>47055106
Destructors are always called in reverse.
>>
>>47055159
That's a property of a plain-jane linked list: to remove node a, just point a-1 -> a+1 and a+1 -> a-1
that said, you are probably thinking about your problem the wrong way: keep in mind that inserts/removals are very rarely the thing you want to optimize if you want to preserve cache locality
>>
>>47055159
there may not be a data structure for that, but if you can predict which elements you would otherwise want to remove, you can just skip executing them in constant time. It doesnt save you the memory, but maybe some execution time.
>>
>>47055159
What language is it? Do you need to remove by index?
>>
>>47055262
I'm pretty sure a linked list is logn(O).
>>
>>47055148
>using column as the x value, new line as the z value and the colour as the y value
seems (very) good to me. with 8-bit RGBA you can get full 32-bit precision for the y value, and the x and z only need to conform to a grid so they don't need more information than the row and column position in the image. i don't know how to read images like that though. it should be possible with a frame buffer, but i don't have experience with that.
>>
>>47055262
got it, thanks. I must be really tired.
>>
>>47055309
not if you save a pointer to the desired node.
>>
>>47055159
>In constant time.
I dunno, that's kinda of hard without buffering your queue into memory, and just removing the last number in the queue associated with that item. Good luck finding a solution, though.

Yes, any search algorithm probably need to be scrapped for using memory instead.
>>
>>47055372
right, if you can predict which element you want to remove. but as soon as you have multiple pointers of potential removal candidates you are back to logn(O).

and thats actually only for an ordered list, an unordered list is n(O).
>>
What is the best text editor to use that isn't harsh on the eyes
>>
>>47055457
are you looking for the best text editor that also presents things legibly, or the most legible text editor that is also usable?
>>
>>47055457
I use emacs with evil.
I would say emacs but it's more awkward with it's keybinds (having to press ctrl and alt all the time). I would say vim but I vim is not as easy to customize and it doesn't have all the potential of emacs, so I say emacs+evil. (Probably start with emacs first and then learn vim keybindings later).
Anything else isn't even worth considering.
>>
>>47055502
minecraft
>>
>>47055502
hackertyper
>>
>>47054186
I'm writing a reverse polish notation calculator in C++ and I can't seem to get it to work. The char check for equating to "enter" on a calc is 'E', and for some reason that condition is evaluating in weird ways.
>>
>>47055457
Any editor with an edgy dark theme
>>
>>47054731
I wonder, could you submit a fizzbuzz or something stupid like pronting an x out depending on the input as a code sample when applying?
>>
i am working on testing my verizon router's security. I dont think an RCE has ever been found for the mi424wr.
>>
>>47055555

It depends what they ask for.
>>
>>47055593
perl web dev jerb just asking for a code sample
>>
Currently learning C, should i keep going or change to C#/C++?
>>
>>47055611
>perl web dev jerb just asking for a code sample

Make a small sample of something perl is super good at it. Something that utilizes regex or what have you.
>>
>>47055632
Learn C, and you'll always have the bare minimum to get a job done without having to known about a bunch of minute details.
>>
>>47055632
Keep going, masterize the language, I did the same thing six months ago; started learning Sepples and Ruby, but I realized that you need to be fluent before starting doing things that doesn't suck.
>>
>>47055457
>dark as my soul theme
>>
>>47055639
Hrm so maybe something that takes user input and spell checks it or something?
>>
>>47055632
C# no, C++ maybe.
>>
>>47055764
>C#
>no
>>
I'm so close to finishing my project..
I'm trying to call a function recursively but it takes vectors as parameters
is there a way so I can call the function like this:
function_call(vector.(0,middle));
function_call(vector.(middle, end));

Is this type of indexing possible?
>>
>>47055777
Correct. Why would you use a walled garden version of Java that doesn't maintain nearly any backwards compatibility with C?
>>
>>47055764
Learn C++ after getting a good grasp on C.
C++ has too much stuff to just switch to it. You want the basic tools provided with C. You can always tell when someone's never used C when
>>
meh, pretty sure this works
(function () {
var primes = [2],
primesIndex = 0,
candidateIndex = 2
candidateSqrt = Math.floor(Math.sqrt(candidateIndex));

while (true) {
candidateIndex += 1;
primesIndex = 0;
candidateSqrt = Math.floor(Math.sqrt(candidateIndex))
while (primes.length > primesIndex) {
if (primes[primesIndex] > candidateSqrt) {
primes[primes.length] = candidateIndex;
console.log(candidateIndex);
break;
}
if (candidateIndex % primes[primesIndex] === 0 ){
break;
}
primesIndex += 1;
}
}
})();
>>
I want to make a music visualizer for android and windows. I want it respond to the frequencies of sound being played and have 3d effects. Should I learn Opengl, java or more c++?
>>
>>47055791
>walled garden
C# supports more relevant platforms than java.
Including iOS.

An its a en ECMA/ISO standard, with several FOSS implementations.

STOP THE FUD
>>
>>47054186
An IRC bot in C++

https://github.com/GreenBagels/greenbot

question I have, how should a dropin build system work? I want a "modules" directory to automatically compile and add the modules to the main code without having to actually add "new Module();" anywhere. that is, I just drop in the files and type ./configure; make and everything works.

I've got it working but I think the way I'm doing it is hacky
https://github.com/GreenBagels/greenbot/blob/master/configure

also any Makefile masters know how to get this shit simpler? seems redundant
https://github.com/GreenBagels/greenbot/blob/master/Makefile#L46-L65
>>
anyone in google summer of code. I don't know what to work on
>>
>>47055895
>C# supports more relevant platforms than java.
kek
>Including iOS.
>An its a en ECMA/ISO standard, with several FOSS implementations.
You mean like Java..?
>>
>>47055859
and improved for some clearity, fixed the missing punctuation. functionally the same code.
(function () {
var primes = [2],
primesIndex = 0,
candidateIndex = 2,
candidateSqrt = Math.floor(Math.sqrt(candidateIndex));

console.log(primes[primesIndex]);
while (true) {
candidateIndex += 1;
primesIndex = 0;
candidateSqrt = Math.floor(Math.sqrt(candidateIndex));
while (true) {
if (primes[primesIndex] > candidateSqrt) {
primes[primes.length] = candidateIndex;
console.log(candidateIndex);
break;
}
if (candidateIndex % primes[primesIndex] === 0 ){
break;
}
primesIndex += 1;
}
}
})();
>>
>>47055927
>kek
Out of arguments?

Also, you can make games for unity with C#.
>>
error: C2440: 'type cast' : cannot convert from 'const QSize' to 'QPoint'


What bullshit is this? Seriously?
>>
>>47055942
>Out of arguments?
Are you? Java supports more relevant platforms and that includes iOS plus it has several FOSS implementations. How do I need to explain this? Why can't I just say kek to your face?
>>
Anyone know what I'm doing wrong,

do I need convertTo ?

trying one of the programing challenges
>>
>>47055927
Java isn't an ECMA/ISO standard, idiot.
>>
>>47055933
skipping evens
(function () {
var primes = [2],
primesIndex = 0,
candidateIndex = 1,
candidateSqrt = Math.floor(Math.sqrt(candidateIndex));

console.log(primes[primesIndex]);
while (true) {
candidateIndex += 2;
primesIndex = 0;
candidateSqrt = Math.floor(Math.sqrt(candidateIndex));
while (true) {
if (primes[primesIndex] > candidateSqrt) {
primes[primes.length] = candidateIndex;
console.log(candidateIndex);
break;
}
if (candidateIndex % primes[primesIndex] === 0 ){
break;
}
primesIndex += 1;
}
}
})();
>>
>>47055106
Unwrapping and wrapping a box.
>>
>>47055159
Not really, although you can use b-linked list (backed by an array) to get log(n) insertions and deletions.
>>
>>47055159
Do you know the position of the item in the queue ahead of time?
>>
>>47055159
Have you thought of maintaining a hashmap that points to list locations in conjuction with the actual list?
>>
I learned about pthreads in class and was told to implement them in C by creating an average, min and max function and having them run in separate threads.
I finished that, over and done with.

The issue is that I wasn't able to do it using arrays of function pointers.
I expected to be able to do something like
void (*p[3]) = {average, min, max}

with each function taking 2 parameters (array and size)
However, the issue is that I segfault everywhere because I don't know how to properly create function pointer arrays, nor how to use pthread_create() and pthread_join() and pthread_exit() in the context of returning values (int).
>>
File: scared.jpg (44 KB, 420x500) Image search: [Google]
scared.jpg
44 KB, 420x500
Okay I have a function. It basically takes a true or false for arbitrary conditions, looks through a list, and removes the items that meet all conditions that are flagged true.

person[] people
function KillPeople(bool killMales, bool killFemales, bool killKids, bool killRedheads...)
person[] potentialVictims = people;

if(killMales) {
foreach (person p in people) {
if(p.gender != male) potentialVictims.remove(p);
} }
if(killFemales) {
foreach (person p in people) {
if(p.gender != female) potentialVictims.remove(p);
} }
if(killKids) {
foreach (person p in people) {
if(p.age<13) potentialVictims.remove(p);
} }
...
foreach (person v in potentialVictims) {
people.remove(v); }

So calling KillPeople(false, true, true, false...) would kill all little girls. Calling KillPeople(true, true, ...) would kill no one because no one is both male and female (tumblr pun not intended).

The problem is if you call false for all conditions, everyone remains on the Victims list and everyone is killed. To get around this I just set up a flag for this specific scenario and instead kill no one.

I'm worried that only this one case requires a flag. Is there another scenario where the code would not work as intended? Is there an easier way to make this function work?
>>
>>47056036
Is it possible for anyone to write a short code segment detailing how to call pthread_create, in a loop iterating through an array of function pointers (multiple parameters), and pthread_join, and pthread_exit to return a single value?
>>
File: itachi.jpg (12 KB, 300x231) Image search: [Google]
itachi.jpg
12 KB, 300x231
I have this code:

if(charSearch(buf,"PING")) {
sendPong(buf, sockfd);
}


Which uses the charSearch function for "PING" and if it sees ping, it uses the function "sendPong"(which just says "PONG"). Now, how would I make it so if a USER on the irc channel says a word, for example, FUCKINGSHITDICK that it'll sendRawPacket to the IRC channel? Obviously, PRIVMSG #channelname :hey kek\r\n. I was thinking something like this

if(charSearch(buf,"FUCKINGSHITDICK")){
sendRawPacket("PRIVMSG #niggersack :heykek\r\n", sockfd);
}


What am I doing wrong here, /g/? Any help is highly appreciated and also if you could show me, it'll be even more appreciated. Thanks in advanced.
>>
>>47056046
Male and female are not genders.
>>
>>47056060
I told you to use strncmp ;_;, if the command isn't found just use an else and use sendRawPacket()
>>
>>47056084
My privilege is fully checked.
>>
>>47056084
I dont even know what this means
>>
>>47056092

Well, I figured something out while messing around with it.

Whenever I do this

 while(1){
rc = recv(sockfd, buf, sizeof(buf), 0);
if(rc > 0) {
buf[rc]='\0';

if(charSearch(buf,"PING")) {
sendPong(buf, sockfd);
}
if(charSearch(buf,"FUCKINGSHITDICK")){
sendRawPacket("PRIVMSG #niggersack :heykek\r\n", sockfd);
}
cout << buf;

}
}


It responds to my console with this

:irc.ku.cx 404 abyrbot #niggersack :Cannot send to channel
:irc.ku.cx 404 abyrbot #niggersack :Cannot send to channel

>>
>>47055975
gc starts to kick in around candidate 90M, can anyone do better?
>>
File: wat.png (11 KB, 750x536) Image search: [Google]
wat.png
11 KB, 750x536
>>47056107

Fixed that problem. Now whenever my bot joins, it spams "heykek" but will say heykek whenever I say FUCKINGSHITDICK

:[email protected] PRIVMSG #niggersack :FUCKINGSHITDICK


This is what I have with my code

 while(1){
rc = recv(sockfd, buf, sizeof(buf), 0);
if(rc > 0) {
buf[rc]='\0';

if(charSearch(buf,"PING")) {
sendPong(buf, sockfd);
}
cout << buf;

if(charSearch(buf,"FUCKINGSHITDICK")){
sendRawPacket("PRIVMSG #niggersack :heykek\r\n", sockfd);
}

}
}
>>
>>47056106
Gender is man/woman masculine/feminine.

Male and female are sexes.
>>
>>47054207
Yes.
>>
>>47056036
>>47056050
My only experience with custom-made threads was with fork(), and using mmap to communicate. If they specially want you to create threads rather than processes, then too bad.
int pid = fork();
if (pid == 0)
we_are_a_child();
else
printf("Child process id: %d",pid);

int fd = open(somefile, O_CREAT|O_RDWR|O_NOATIME, S_IRUSR|S_IWUSR);
char *ptr = mmap(NULL, 256, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

// communicate via memory
...

munmap(ptr, 256);
close(fd)


In practice, you're better off using that provided by toolkits rather than having to roll your own.
>>
>>47056132
>using synonyms to define distinction
Oh the brave new world we live in.
>>
>>47056128
>it spams "heykek" but will say heykek whenever I say FUCKINGSHITDICK
>if(charSearch(buf,"FUCKINGSHITDICK"))
>sendRawPacket("PRIVMSG #niggersack :heykek\r\n", sockfd);
>:heykek\r\n
>>
>>47056144

Worded that wrong, sorry. As soon as it joins, it spams "heykek" over and over. Shouldn't it only do it once?
>>
>>47056141
Oh well.
I'm already familiar with fork() to make buttloads of processes, and how to communicate between parent and children with exit() though.
mmap seems like an interesting alternative though.
>>
>>47056046
I kinda figured it out. If there are no conditions to meet, then everyone meets those conditions and everyone is flagged for death. What I thought was a bug is actually a feature.
>>
>>47054974
I use Linux and OP image is mai waifu.
>>
>>47054615
Read it in via scanf? what the fuck are you doing?
>>
>>47054741
>Can't read in strings with ease.
>Calls himself a C elitist.
Fuck off back to Python.
>>
>>47056151
>Shouldn't it only do it once?
I don't know, maybe you should flush your buffer before getting the next message, Because there would be any "traces"/"leftovers" (I don't know if that word is correct) from buf.
The only thing I see to clean buf is:
buf[rc]='\0';
, if rc is at a position after "FUCKINGSHITDICK" substring, then it would create an infinite loop.
>>
>>47054615
>>47056184
scanf(fp, "%[^\n]%*c", buffer);
>>
How can I apply the based lifestyle for programming?
>>
>>47054615

You can adapt >>47056208 by using a field width specifier, reading each line in chunks, and dyanamically resizing your line-buffer as needed. Boyah, no buffer overflows ever. I used to call it gets_unlim().
>>
>>47056204

Yeah, for some reason, it doesn't change anything.

 while(1){
rc = recv(sockfd, buf, sizeof(buf), 0);
if(rc > 0) {
buf[rc]='\0';

if(charSearch(buf,"PING")) {
sendPong(buf, sockfd);
}
cout << buf;
}
buf[rc]='\0';
if(charSearch(buf,"hey")){
sendRawPacket("PRIVMSG #niggersack :hey bro\r\n", sockfd);
}else{

}


}


Continues to spam as soon as it joins
>>
>>47056257
Change rc to a literal 0.
buf[0] = '\0';
>>
>>47056257
Do you ever clear your buffer between checks?
>>
File: ss+(2015-03-18+at+02.31.14).png (41 KB, 1014x578) Image search: [Google]
ss+(2015-03-18+at+02.31.14).png
41 KB, 1014x578
>>47056273

while(1){
rc = recv(sockfd, buf, sizeof(buf), 0);
if(rc > 0) {
buf[0]='\0';

if(charSearch(buf,"PING")) {
sendPong(buf, sockfd);
}
cout << buf;
}
buf[rc]='\0';
if(charSearch(buf,"hey")){
sendRawPacket("PRIVMSG #niggersack :hey bro\r\n", sockfd);
}else{

}


}
>>
>>47056273
Also, that should be just before entering the while, before calling recv().
>>
>>47056294
*after entering the while, I'm tired fuck.
>>47056292
>>
>>47056294

Like this?

 int rc;
int MAXSIZE = 65535;
char buf[MAXSIZE];
while(1){
rc = recv(sockfd, buf, sizeof(buf), 0);
if(rc > 0) {
buf[rc]='\0';

if(charSearch(buf,"PING")) {
sendPong(buf, sockfd);
}
cout << buf;
}
buf[0]='\0';
if(charSearch(buf,"hey")){
sendRawPacket("PRIVMSG #niggersack :hey bro\r\n", sockfd);
}else{

}


}


No spamming but no response when I say 'hey'
>>
>>47054615
This is the thing, people always complain about how strongly typed and overdone Java is to do simple tasks, but compare the code for just reading a fucking line in C vs Java. And string tokenising makes it even worse. I like both languages, but for working with files Java is much more suitable.
>>
>>47056324
while(1){
buf[0]='\0';
rc = recv(sockfd, buf, sizeof(buf), 0);
>>
>>47056333

Lol, did nothing.

  while(1){
buf[0]='\0';
rc = recv(sockfd, buf, sizeof(buf), 0);
if(rc > 0) {
buf[rc]='\0';

if(charSearch(buf,"PING")) {
sendPong(buf, sockfd);
}
cout << buf;

buf[0]='\0';
if(charSearch(buf,"hey")){
sendRawPacket("PRIVMSG #niggersack :hey bro\r\n", sockfd);
}else{

}
}
}


Bot connects, says "Bot successfully connected!" ( sendRawPacket("PRIVMSG #niggersack :Bot successfully connected!\r\n", sockfd); ) then continues to send pongs back to the server and stays idle
>>
>>47056376
Try deleting the second >buf[0]='\0';, also what is doing that cout there. The main problem is what >>47056283 said.
>>
>>47056394

The second buf causes it to spam over and over without me even saying hey. The cout outputs the buffer (console) so I can use my charSearch function. Would I be clearing the buffer of a char?
>>
Sorry, but could someone explain to me why this recursive copy function is causing a segmentation fault?
Am I even allocating the new node correctly?
void make_copy(node * & destination, node * source)
{
if(!source)
{
destination = NULL;
return;
}

make_copy(destination->left, source->left);

destination = new node;
destination->data = source->data;

make_copy(destination->right, source->right);
}
>>
>>47056423
This is for a binary search tree by the way
>>
>>47056423
void make_copy(node * & destination, node * source)

What is the meaning of that line?

I think you mean
void make_copy(node **destination, node * source)
{
if(!source)
{
*destination = NULL;
return;
}

make_copy( (*destination)->left, source->left);

*destination = new node;
(*destination)->data = source->data;

make_copy((*destination)->left, source->right);
}

untested, but makes more sense.
>>
>>47056517
node * & destination


is passing a pointer by reference, giving the function access to change the variable while source is just passed in to provide data to be copied.

node **destination


would be a 2D pointer which I don't have in this case.
>>
>>47056418

a-anyone pls
>>
>>47055975
prime tornado
(function () {
var primes = [2],
primesIndex = 0,
candidateIndex = 1,
candidateSqrt = Math.floor(Math.sqrt(candidateIndex)),

eightySpaceString = " ",
wave = [""];
waveIndex = 0,
waveAmplitude = 70,
waveIncrements = 314151,
piIncrements = Math.PI / waveIncrements,
piIncrementIndex = piIncrements,

(function () {
console.log("making waves");
while(true){
console.log(piIncrementIndex);
if(wave.length === waveIncrements){
console.log("breaking");
break;
} else {
wave[wave.length] = eightySpaceString.slice(0, Math.floor(Math.sin(piIncrementIndex) * waveAmplitude));
}

piIncrementIndex += piIncrements;
}
})();

console.log(primes[primesIndex]);
while (true) {
candidateIndex += 2;
primesIndex = 0;
candidateSqrt = Math.floor(Math.sqrt(candidateIndex));
waveIndex = (waveIndex + 1) % waveIncrements;
while (true) {
if (primes[primesIndex] > candidateSqrt) {
primes[primes.length] = candidateIndex;
console.log(wave[waveIndex] + candidateIndex);
break;
}
if (candidateIndex % primes[primesIndex] === 0 ){
break;
}
primesIndex += 1;
}
}
})();
>>
>>47054741
>i'm a C elitist!
>I like torturing myself
>i'm a fanboi and don't realize that different languages have different uses
>Id rather limit myself and try to hammer with a screwdriver

Seriously, fuck people like you... you're more pretentious than Mac users.
>>
>>47055917
No but fuck, I'm wondering that too.
>>
>>47056418
Technically no, you just need to be sure everytime a message is read it will be saved at the starting position of buf, that way charSearch will work as expected. This can be achivied by: 1- Making sure you're saving the message at the beginning of buf, or, 2- Cleaning all the buffer (a lot of overhead). Try to printing buf everytime you read a message to see the actual problem and verify the charSearch funtion, maybe there's something wrong.
>>
>huge ass c++ library that takes hours to compile
>>
>>47056650

How would I even go about doing this? I'm horrible at just reading text, once I get an example, I can do it.
>>
>>47056423
I'm not that familiar with C++ but I think you should be allocating destination before the first recursive call, not after.
>>
Is there a better way to round an integer to the nearest multiple than this?

(num / (float)multiple) * multiple
>>
>>47056670
Just print buf, just like debugging any other variable, for example I think your problem is possibly this:
// iteration
// get string
Enter message: hey fgt
// buf will have "hey fgt", next iteration
// get string
Enter message: kek
// buf will have "hey fgt kek"

The only way to know is printing buf every iteration and checking charSearch just to make sure.
>>
>>47056696
Ah... yep. That was it.
Makes sense now that I think about it.
>>
>>47056652
>compiling the library yourself
>not ripping out huge parts of it
>>
File: 176.png (16 KB, 1019x737) Image search: [Google]
176.png
16 KB, 1019x737
I'm trying to make a simple paint program but my lines are getting weird bumps on them. My algorithm is just to draw a line between the new and previous mouse positions when it moves. Anyone know what might be causing this?
>>
>>47056755
enjoy getting sued
>>
>>47054650
ftell is not a good way to get the filesize, use _stat for it
>>
>>47056792
1. Are there actually licenses where the source code is available but illegal to modify? I wouldn't know since I don't use libraries that aren't GPL/LGPL.
2. How would they know?
>>
>>47056782
Correct it afterwards using anti-alias or something I don't know. Keep track of where the line goes and then apply smoothing afterwards.
>>
>>47056636
wave fixed from half period, to full period of pi
(function () {
var primes = [2],
primesIndex = 0,
candidateIndex = 1,
candidateSqrt = Math.floor(Math.sqrt(candidateIndex)),

eightySpaceString = " ",
wave = [""];
waveIndex = 0,
waveAmplitude = 35,
waveIncrements = 314151,
piIncrements = Math.PI * 2 / waveIncrements,
piIncrementIndex = piIncrements,

(function () {
while(true){
if(wave.length === waveIncrements){
console.log("breaking");
break;
} else {
wave[wave.length] = eightySpaceString.slice(0, Math.floor((Math.sin(piIncrementIndex) + 1 ) * waveAmplitude));
}

piIncrementIndex += piIncrements;
}
})();

console.log(primes[primesIndex]);
while (true) {
candidateIndex += 2;
primesIndex = 0;
candidateSqrt = Math.floor(Math.sqrt(candidateIndex));
waveIndex = (waveIndex + 1) % waveIncrements;
while (true) {
if (primes[primesIndex] > candidateSqrt) {
primes[primes.length] = candidateIndex;
console.log(wave[waveIndex] + candidateIndex);
break;
}
if (candidateIndex % primes[primesIndex] === 0 ){
break;
}
primesIndex += 1;
}
}
})();
>>
>>47056782
Post your code maybe.
>>
>>47056782
Try using Bresenham's algorith for drawing lines... if you aren't already
>>
>>47056837
fixed some gramatical errors
(function () {
var primes = [2],
primesIndex = 0,
candidateIndex = 1,
candidateSqrt = Math.floor(Math.sqrt(candidateIndex)),

eightySpaceString = " ",
wave = [""],
waveIndex = 0,
waveAmplitude = 35,
waveIncrements = 314151,
piIncrements = Math.PI * 2 / waveIncrements,
piIncrementIndex = piIncrements;

(function () {
while(true){
if(wave.length === waveIncrements){
break;
} else {
wave[wave.length] = eightySpaceString.slice(0, Math.floor((Math.sin(piIncrementIndex) + 1 ) * waveAmplitude));
}
piIncrementIndex += piIncrements;
}
})();

console.log(primes[primesIndex]);
while (true) {
candidateIndex += 2;
primesIndex = 0;
candidateSqrt = Math.floor(Math.sqrt(candidateIndex));
waveIndex = (waveIndex + 1) % waveIncrements;
while (true) {
if (primes[primesIndex] > candidateSqrt) {
primes[primes.length] = candidateIndex;
console.log(wave[waveIndex] + candidateIndex);
break;
}
if (candidateIndex % primes[primesIndex] === 0 ){
break;
}
primesIndex += 1;
}
}
})();
>>
>>47056782
eww
>>
>>47056839
Which part?

>>47056849
I'm using OpenGL
>>
working on a TeamSpeak 3 bot written in Haskell.
>>
>>47056947
>Which part?
The part where you find the mouse position and calculate where to draw the line.
>>
>>47056947
I assume its rounding, the mouse is touching the top of the pixel so its setting both?
>>
>>47056964
That's really good on the eyes.
>>
File: hey-guys.jpg (38 KB, 400x400) Image search: [Google]
hey-guys.jpg
38 KB, 400x400
>Boring at work
Do you guys have any project on github that needs a contribute?
Let me join, preferable in Javascript project or PHP project.
>>
>>47056964
 x |> y = y x 


you OCaml?
>>
>>47056978
the theme is zenburn
>>
>>47056964

COLORS FUCKING NOW PLEASE
>>
>>47057051
actually no, but I knew of it from ocaml and it seemed to make more sense here (filtering events as you go along is confusing when function composition is shown in the "backwards" way)
>>
>>47056964
God damn that's some aesthetic looking code. Makes me want to learn Haskell.
>>
>>47057070
would recommend/10
http://learnyouahaskell.com
http://book.realworldhaskell.org/
https://wiki.haskell.org/Haskell
>>
>>47057069
function application*
and yeah I use that operator all the damn time.
>>
>>47057122
oh you were talking about |-> ... whoops my bad.
>>
>>47057119

Don't be a greedy jew and share your colors.
>>
>>47057139
>>47057056
>>
>>47057139
I already said the color theme is zenburn, learn to read
>>
>>47057142


thanks my nigga. clearly wasnt paying attention. my bad.
>>
Is there a place to get a bunch of notepad++ themes?
>>
also here is my emacs config if anyone cares:
http://pastebin.com/raw.php?i=i9mZ6N7Q
>>
here's my take on the retardbox: >>47057145

>https://programmers.stackexchange.com/questions/268089/which-weak-algorithmic-strategies-i-have-that-lead-me-to-failing-coding-this-sim
>going to university for this
>not even learning this
>>
File: 1396571416586.jpg (34 KB, 278x278) Image search: [Google]
1396571416586.jpg
34 KB, 278x278
>>47057173
>>
File: im_grate.jpg (107 KB, 375x530) Image search: [Google]
im_grate.jpg
107 KB, 375x530
>>47054435
The C programming language and Introduction to Algorithms
>>
Thank you for using an anime image.
>>
Got my Lisp compiler self-hosting yesterday. Feels pretty good.
>>
>>47057250
public static void main(String[] args) {


int size = 9;

for ( int i = 1; i <= size; i++) {

if ( i <= size/2 ) {
for ( int k = 1; k < i; k++ ) {
System.out.print(" ");
}

System.out.print("*");

for(int j = i; j < size-i; j++) {
System.out.print(" ");
}

System.out.print("*");
}
else if ( i == (size/2)+1 ) {
for ( int k = 1; k < i; k++ ) {
System.out.print(" ");
}
System.out.println( "*");

}
else {

// for ( int k = 0; k < (size/2) -1; k++) {
// System.out.print(" ");
// }
//
// System.out.print("*");
//
// for ( int j = i; j > size-i; j-- ) {
// System.out.print(" ");
// }
//
// System.out.print("*");

}

System.out.println();
}


Somebody should make a CS grad maymay out of this
>>
Being forced to write in js right now
>>
>>47055964
Yes you need to convert values to their respective types.

If it needs to be a string use .toString();

If it needs to be a decimal use decimal.Parse();

If it needs to be an int use int.Parse();
>>
>>47058200
>.toString
THIS ISNT JAVA YOU FUCKWAD
>>
C#/xna. Clicks register when window doesn't have focus. I add a game.IsActive check for the check for a click, and it starts working mostly as normal. However, if I click the window at the bottom of the screen to minimize it, clicks are still registered. If I click on another window to put the game out of focus, or click on the "-" icon to minimize it, that doesn't happen.

Putting in a Console.WriteLine(game.IsActive) in the game1.cs update files shows that clicking on the window icon to minimize sets IsActive to false for an number of frames inconsistent across tests, but get numbers like 8 - 40 until it switches back to true without me doing anything.

wat do
>>
>>47058173
>>47051634
>>
>>47058293
t.h.a.n.k.y.o.u.
>>
I am trying to do some responsive browser javascript, but I am having trouble with setTimeout();

anyone have any tips?

do I just call every function with setTimeout( function(){}, 0);?
>>
>>47058364
what are you trying to accomplish?
>>
>>47058385
trying to do some ascii animation by modifying html elements.
>>
File: IMG_20150317_123941.jpg (27 KB, 720x175) Image search: [Google]
IMG_20150317_123941.jpg
27 KB, 720x175
How to make game: the sequel

I'm not very experienced at programming, and I don't really know what to mess around with.
My target is to create a clone for Windjammers, for the NEO-GEO. I would love implementing a netplay feature.
What language would be the most suitable for such task? Is there some useful tutorial or something that might make the difference?

Thanks in advance, /g/.
>>
What am i doing wrong?
>>
Would this work?

#include <iostream>
#include <String>
using namespace std;
int main(void){
char board[]; = { "a", "b", "c", "d", "e", "f", "g", "gif", "h", "hr", "k", "m", "o", "p", "r", "s", "t", "u", "v", "vg" "vr", "w", "wg" };
cout << board[2]; << endl; // should cout /b/
return 0;
}


If so, how would I go about taking a users input(cin) and looking into the string board for that number and if it's not in the string, prompt a error message. Of course I'd do if, else if, and an else statement. But how exactly so?
>>
>>47058569
#include <iostream>
#include <string>

int main(int, char **)
{
std::vector<std::string> boards = { "a", "b", "c", "d", "e", "f", "g", "gif", "h", "hr", "k", "m", "o", "p", "r", "s", "t", "u", "v", "vg" "vr", "w", "wg" };

std::string input;
std::cin >> input;

auto it = boards.find(input);
if(it == boards.end())
{
std::cout << "No board found.\n";
return 0;
}

std::cout << *it << '\n';
return 0;
}
>>
>>47058599

Ayylmao. Thanks bro. Appreciate it.
>>
>>47058539
Why is it returning 0?
>>
Any resource to program AI
>>
>>47058629
it tells the OS that its done.
>>
>>47058539
byte alignment and packing. Fix with:
#pragma pack(push)
#pragma pack(1)
// your structs
#pragma pack(pop)
>>
>>47058599

Would this work?

#include <iostream>
#include <string>

int main(int, char **)
{
std::vector<std::string> boards = { "a", "b", "c", "d", "e", "f", "g", "gif", "h", "hr", "k", "m", "o", "p", "r", "s", "t", "u", "v", "vg" "vr", "w", "wg" };
std::cout << "What board? ";
std::string board;
std::cin >> board;

auto it = boards.find(board);
if(it == boards.end())
{
std::cout << "Board not found. Please enter in a valid board.\n";
return 0;
}
std::cout << "Thread name? ";
std::string thread;
std::cin >> thread;

auto th = thread.find(thread);
if(th == thread.end()){
std::cout << "No threads with the keyboards you specified are currently on " << board << std::endl;
std::cout << "Would you like to search for another keyword?(yes/no): ";
std::string yon;
std::cin >> yon;
if(yon == 'yes' || yon == 'YES'){
// we need to make a function to search for another thread in the specified board they user decided
} else if(yon == 'no' || yon == 'NO'){
std::cout << "Have a great day! Thanks for using this program\n";
break;
} else {
std::cout << "Please enter in a valid input or learn how to read, anon!";
// we need to make a function that sends the user back to searching the keyword on the specified board again
}
}
std::cout << *it << *thread << std::endl;
return 0;
}
>>
>>47058654
That wouldn't do anything because im not writing the structs directly.
>>
>>47058654
I fixed it anyway, turns out i was using an old version of the format.
>>
>>47058678
You have to pass the correct sizeof(youre_struct) to header.bytes rather than the size of an int.
>>
>>47058328
this gave me an idea.

    void box(String str) {
char[] chars = str.toCharArray();
int size = chars.length;
char[][] arr = new char[size][size];
for(int i = 0; i < size; ++i) {
Arrays.fill(arr[i], ' ');
}
final int j = size - 1;
for(int i = 0; i < size; ++i) {
arr[i][0] = chars[i];
arr[0][i] = chars[i];
arr[i][j] = chars[i];
arr[j][i] = chars[i];
arr[i][i] = chars[i];
arr[i][j - i] = chars[j - i];
}
for(int i = 0; i < size; ++i) {
System.out.println(arr[i]);
}
}


it only works properly with strings ending with the same char as it starts with.

box("poop");

poop
oooo
oooo
poop


box("daily programming thread");

daily programming thread
aa aa
i i e i
l l r l
y y h y
t
p p p
r r g r
o o n o
g g i g
r r m r
a am a
m am m
m r m m
i g i i
n o n n
g r g g
p
t t t
h y h h
r l r r
e i e e
aa aa
daily programming thread


box("/dpt/");

/dpt/
dd td
p p p
td tt
/dpt/
>>
>>47058640
I see. From what I can see you're missing something that tells the compiler what header size you have. But I don't code in general, and I feel something is missing. You mostly have it completed, but you need to tell it tell it this is the header size.
>>
An Python algorithm to search through a list of inputted numbers to see if there are two numbers that add up to exactly 100.

It's a Big-O exercise for uni
>>
>>47058717
Must it be faster than O(n^2)
>>
>>47058666
You don't have threads defined, there's no need for the break also.
>>
Trying to modify Chanu to save and share images under Unix time instead of post number.
I've never developed for Android before, but Java is known to me

Dev is a cuck
>>
>>47058692
the code is messy but i've officially wasted way too much time on this already

    void box(String str) {
char[] chars = str.toCharArray();
int foo = chars.length;
int foobar = (foo << 1) - 1;
char[][] arr = new char[foo][foobar];
for(int i = 0; i < foo; ++i) {
Arrays.fill(arr[i], ' ');
}
for(int i = 0, k = 0, n = 0; i < foo; ++i, ++k) {
arr[i][0] = chars[i];
arr[i][foobar - 1] = chars[i];

arr[0][n] = chars[k];
arr[foo - 1][n] = chars[k];
arr[i][n] = chars[k];
arr[i][foobar - 1 - n] = chars[k];

++n;

if(n < foobar) {
arr[0][n] = ' ';
arr[foo - 1][n] = ' ';
arr[i][n] = ' ';
arr[i][foobar - 1 - n] = ' ';
}

++n;
}

for(int i = 0; i < foo; ++i) {
System.out.println(arr[i]);
}
}


box("tyrannosaurus rekt");

t y r a n n o s a u r u s   r e k t
y y y y
r r r r
a a a a
n n n n
n n n n
o o o o
s s s s
a a a a
u u u u
r r r r
u u u u
s s s s

r r r r
e e e e
k k k k
t y r a n n o s a u r u s r e k t
>>
>>47059019
Is this the successor of tornado?
>>
File: 1420452045485.jpg (142 KB, 643x642) Image search: [Google]
1420452045485.jpg
142 KB, 643x642
>>47054186
>tfw job interview next morning

never coded a line
>>
>>47059032
it might have some meme potential because of the stackoverflow question. drawing different patterns with strings like the tornado and this "text crossbox", and other patterns too, makes for good practice without taking up too much time. i'm curious to see how the square text crossbox (one space between each horizontal character) would be implemented in other languages.
>>
>>47058717
O(n)

(assuming 0 <= n <= 100, can easily be adapted to any range though)

keep an array of integers with indices 0 through 100

go through the list, and increment array[n]

go through the array from 0 through 50, and check array[100 - n] != 0
>>
>>47059285
>go through the array from 0 through 50, and check array[100 - n] != 0
50 is a special case, you need to check array[50] >= 2
>>
I'm working on the next big chat program/protocol: Memechat.
>>
>>47059285
>go through the array from 0 through 50, and check array[100 - n] != 0
and array[n] != 0 too of course
>>
>>47055964
Why are you storing quantity in a string? Are you fucking dumb?
>>
File: sdftext.png (18 KB, 741x222) Image search: [Google]
sdftext.png
18 KB, 741x222
Rendering text with signed distance fields. They produce crisp text, but they're hard to control. I can outline the text, but the moment I try to anti-alias it, things go to hell. I don't know if I'm generating the SDF texture incorrectly, or if my fragment shader is wrong. I've found several SDF examples that all do things slightly differently, yet they produce mostly similar results, but if I try to duplicate their results (even use their shaders and textures!), I get crappy results and I can't find out why. I just wanted to draw crisp, outlined and anti-aliased text on arbitrary 3D flat surfaces :-(

At least the Unicode part works.
>>
>>47059285
This assumes all list entries are non-negative.
>>
Hi /g/
I'm new to c++ and my program segfaults on this setter:
void snext(_Inter* new_next){_next = new_next;};

I simply don't now why. Does anyone have an idea ?
>>
>>47059513
You can find out minimal and maximal elements on input and take them into account. The code shouldn't change too much.
>>
>>47058717
Maintain a max-heap and min-heap.
If the max+min>100, drop the max element. <100, drop the min element.
Should be O(n*log n) if I'm not mistaken.
>>
A simple TWM for Windows, tiling Windows manager.
Done:
>create zones for window placement
>actually place windows
To Do:
>multiple zone configurations
>exclude programs
>borders
>>
>>47059513
you can keep another array for negative numbers, or pack them into the one array with an offset if you know the range.
if(n < 0) ++negArr[-n]; else ++posArr[n];
>>
>>47059391
What does your SDF texture image look like?
>>
Tornado'd crossboxes look pretty stupid
################
# ###
# # ##
# # ##
# # ##
# # ##
# # ##
## ##
# ## #
# ## #
# ## #
# ## #
# ## #
# ## #
####
################
>>
File: lunar-messaging.png (362 KB, 1008x726) Image search: [Google]
lunar-messaging.png
362 KB, 1008x726
wrapped up a barebones API (PHP) for a messaging app im working on. , has lots's of error checks, a really simple auto class loader, an ExitCode system, and a handfull of other things. That and my restful API has a sexy as fuck URL scheme.

Works super awesome and super simple.


now to actually make the app talk to this shit, and figure out how to get mcrypt in PHP and Android to play nicely.
>>
>>47059925

kek
>>
Dis shit gets me every time
void swap(int *a, int *b){
*a = *a + *b;
*b = *a - *b;
*a = *a - *b;
}
Pls tell me if I fucked up the pointers
>>
>>47058277
Bump.

Any advice on debugging, at least?
>>
>>47060080
Use code tag for your code.

Also, what is it supposed to do? If it's a simple swap, shouldn't the first *a be a int temp ?
>>
>>47054615
>>47054633
>>47054650
>>47054795 etc
am I missing something? why not:
#include <stdio.h>

int main (int argc, char **argv) {
char line[1024];
FILE *file = fopen(argv[1], "r");

fgets(line, sizeof(line), file);
printf("%s", line);
fclose(file);

return 0;
}
>>
I went to an interview for a programming job and they had that one "swap the values of variables a and b without making a third varibale" question in one of their tests.
I wrote "why the fuck would you do that" as an answer.
I think they rejected me.
>>
>>47060080
it should work
but why not use void* for the parameters?
>>
>>47060080
void swap(int *a, int *b) {
temp = *a;
*a = *b;
*b = temp;
}

temp is an int
>>
>>47060133
Don't always not do that


I did a similar thing, the question was if you can setup server sessions, develop a session concept for client end session managing.

Wrote a really long paragraph about how absolutely stupid this is, and i dont care "why the server is limited", you're a corp, build or buy a new server.


They absolutely loved my answers, but i didnt get the job because i didnt know laravel at the time.
>>
File: 1327766884468.jpg (35 KB, 314x261) Image search: [Google]
1327766884468.jpg
35 KB, 314x261
The more I socialize with CS majors the more I doubt the integrity of it as a proper academic field of study. Send help.
>>
>>47060080
>>47060113
>>47060144
>>47060152

without temp:

X := X XOR Y
Y := X XOR Y
X := X XOR Y
>>
>>47060133

Who knows. They're expecting the arithmetic trick or the XOR trick, both of which are very bad and hard to read.
>>
Well speak of the devil,

look at: >>47060167

for reasons why you should never ever do that.
>>
>>47060117
get line 1 into 'line', process it, put line 2 of the file into 'line', etc.
the code you posted just gets the first 1024 characters, including newlines.
Your code would assume a the first line is 1024 chars, and only get the first line.
>>
>>47060133
>>47060172
the XOR swap is one of easiest bit manipulation tricks you can do. they might want a programmer who possesses a wide variety of skills, which might include bit manipulation for performance reasons or working with boolean algebra in general. besides pointing out incompetent/inexperienced programmers it also helps to weed out work candidates with shit attitudes "fuck you i refuse to do this task because it's retarded".
>>
>>47060188
All of which you can change, or make dynamically sized on your own. Change the fgets to a while-loop if you want something other than the first line.
>>
>>47060207

Maybe, but if you're expecting someone who comes in to right-away understand all the tricks, then you're going to have a bad time. That sort of stuff gets smashed into your brain over a long career, not after 4 years of college.
>>
>>47060222
they get a lot of applicants though. depending on the company they probably have a lot of people to pick and choose from. that particular question might not be a set requirement to pass the interview, but if you fail a significant number of the questions or indicate problems with attitude ("why the fuck would you do that") then that is probably a pretty good indicator that you're not suitable for the job.
>>
>>47060181

Wat?
>>
>>47060248

I'd say it really depends, but that's just my position. If you're looking for junior devs (and I'm not sure that's what that question is for) who are actually good at programming, you are going to have a very hard time. The idea is to get them onboard and then mold them into good programmers through years of tedious work and boring break-room discussions.
>>
Although, you should probably write: "I haven't learned this trick yet" rather than "fuck off :^)"
>>
>>47060248
Give them a floppy which has tornado text programmed in multiple languages.
Guaranteed hire.
Thread replies: 255
Thread images: 31

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.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.