[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


Thread replies: 323
Thread images: 22

Previous thread at >>51874414

What are you working on, /g/?
>>
first for Java
>>
First for Java
>>
first for filtering averaging two ints meme
>>
Nth for c#
>>
File: Jobs_2003_rev1.jpg (2MB, 2370x2166px) Image search: [Google] [Yandex] [Bing]
Jobs_2003_rev1.jpg
2MB, 2370x2166px
Ask a programming literate anything.
>>
First for Java
>>
OOP in languages like Java and C# and C++ is poorly implemented. At least in C++ you can get around it.
>>
>old thread is still on page one
>must be time to make a new thread.
I swear you guys are worse than /vg/ with this shit.
>>
Help me understand entropy >>51880088
>>
>>51880441
see >>51880408
>>
>>51880422
Why did you post a pic of someone who isn't programming literate?
>>
>>51880435
OOP is a tool for reducing code duplication and achieves the task well enough in C++, C# and Java.
>>
>>51880446
>trap thread
What does this mean?
>>
File: 18211.png (98KB, 400x300px) Image search: [Google] [Yandex] [Bing]
18211.png
98KB, 400x300px
>>51880435
>the Ctard is at it again
>>
>>51880465
it's a /dpt/ thread with the OP promoting faggotry such as crossdressing. lately we've been having a very persistent troll that has been forcing himegoto pics and most of the time he's posted the thread before the bump limit which is a big no-no. it might be the same person as the one that's been posting 3D traps, just that he's moved on to himegoto because he can get away with it a lot of the time.
>>
File: 1.png (29KB, 1209x705px) Image search: [Google] [Yandex] [Bing]
1.png
29KB, 1209x705px
Making a Caesar Cipher, But wondering how to avoid symbols being included within the shifts. Any tips? I feel like I've made some kind of real obvious mistake.
>>
>>51880442
>>51880088
Those 40 minimum bits include storing information about the order of your cards. Because you don't care about order, you're able to store them in lesser amount of bits.
>>
>>51880381
Thank you for not posting an anime image.
>>
>>51880554
Nevermind guys, I figured it out myself!
>>
File: steve-jobs.png (118KB, 750x233px) Image search: [Google] [Yandex] [Bing]
steve-jobs.png
118KB, 750x233px
>>51880450
>apple
>mac os
>objective-c
>next
>nextos
>dylan
>swift
>>
>>51880637
>implying objective c is good
>>
>>51880575
Thanks I feel super dumb now
The minimum would actually be 52^7 / (7!) right?
Apparently that's only 20 bits which means my thing is terrible
>>
>>51880503
Himegoto anon here, I'm not posting anything but himegoto.
You're thinking of someone else.
>>
>>51880657
log(52^7 / (7!))/log(2) = 27.6038700086
>>
>>51880381
trying to understand the following Python quine
a='a=%s;print a%%`a`';print a%`a`
>>
>>51880685
I'm too braindead to think apparently, I'll just take your word and fail to form an opinion on it.
>>
File: K&R himegoto.jpg (159KB, 500x700px) Image search: [Google] [Yandex] [Bing]
K&R himegoto.jpg
159KB, 500x700px
>>51880503
What's wrong with himegoto?
>>
>>51880726
It means you were much closer to it than you thought. ~27.6 bits, not 20 bits.
>>
>>51880727
it gets really fucking old to see it every goddamn thread especially when it's forced by posting before the bump limit
>>
>>51880727
himegoto is cute and i would be interested in fapping to it but its not really related to programming and i dont like when people give anime haters an excuse to shit up 4chan even more with their offtopic complaints which never get cleaned up
>>
Literally what's the point of classes? They're useless as fuck
>>
Anyone can confirm this shit works with every number?
/* Averages two ints without overflow */

#include <stdio.h>
#include <stdlib.h>

int avg(int a, int b)
{
if (a % 2 != 0 || b % 2 != 0) { /* if one of the numbers is odd ... */
if (a % 2 != 0 && b % 2 != 0) { /* it checks if both are odd */
if (a < 0 || b < 0) {
return a/2 + b/2 + (a%2); /* magic */
}
return a/2 + b/2 + (a%2 + b%2); /* division truncates */
} else { /* if just one is, then add 0.5 */
return a/2 + b/2 + 0.5;
}
} else { /* if they are both even */
return a/2 + b/2;
}
}

int main(int argc, char *argv[])
{
if (argc == 3) {
int a, b;
a = atoi(argv[1]);
b = atoi(argv[2]);
printf("%d", avg(a, b));
} else {
printf("%d", avg(-1, -1));
}
return 0;
}
>>
>>51880785
To bind code and data together.
>>
>>51880761
so basically it's a non-issue, ok
>>51880771
>fapping to himegoto
what the fuck is wrong with you, you homo

>>51880785
think of structs, except you can embed functions inside of them, real functions, not just pointers to functions
>inb4 what's the point of structs? They're useless as fuck
>>
>>51880793
Checked it, doesn't work.
>>
>>51880793
>return a/2 + b/2 + 0.5;
Bad form, will pollute compiler outputs with warnings about truncation. Do an explicit cast.
>>
>>51880793
That shit can be reduced.
>>
>>51880727
>>
>>51880812
>>51880819
>>51880814
Trying to get it working before thinking on reducing it. Yup, it doesn't work with some stuff. Working a bit more on it.
>>
>>51880785
To create composite types and interface with them.
>>
>>51880839
>>51880793
>atoi
Don't use atoi, it's unsafe, use strtol
>>
>>51880839
int avg(int a, int b){
return ((double)a + b)/2;
}


Here. Don't torture yourself.
>>
>>51880793
kek
>>
>>51880858
Just check to make sure every character in the string is a numeric value, and add an exception for the first char being a '-' char for negative numbers.
>>
>>51880831
Thank you!
>>
>>51880875
>Just check to make sure every character in the string is a numeric value, and add an exception for the first char being a '-' char for negative numbers.
Which strtol does for you.... Seriously, just use it instead.

char* sptr;
int number = strtol(argv[1], &sptr, 0 /* base 0 = decimal, octadecimal and hexadecimal */);
if (sptr == NULL || *sptr != '\0') { fprintf(stderr, "%s is not a number you idiot\n", argv[1]); exit(1); }
>>
>>51880864
That will still round down the result when it's cast back to an int. Better would be:
int avg(int a, int b){
return ((double)a + b)/2 + 0.5;
}
>>
>>51880911
It depends entirely of preference. I think integer average of 4 and 5 should be 4, nd for my problem it might be the best approach.
>>
Python should never be a first language.
I never would have appreciated how easy everything is if I hadn't written everything in C for so long.
Praise the snake.
>>
>>51880930
>>51880911
The problem is, though, that in the real world the average of any two integers is a real number, not an integer.
>>
>>51880953
Thankfully we are not in real world, we are just trying to apply averaging to solve a particular problem.

If you want floating point result, just change return type.
>>
how to average three ints in C
>>
>>51880971
WEBCÜCK DETECTED
>>
>>51880974
int avg(int a, int b, int c)
{
return (a + b + c)/3
}
>>
>>51880998
Not again for fuck's sake...
>>
>>51880930
>>51880953
>>51880911
>>51880875
>>51880869
>>51880864
>>51880858
>>51880812
Which test cases should I use to know if it works or not?
>>
>>51881000
breaks with ints larger than
715827883
>>
>>51880756
26.9953363841
>>
How long have we been trying to average two ints in C now?
>>
>>51881000
int average = avg(INT_MAX, 2, 3);
>>
File: aaaaa.png (83KB, 694x801px) Image search: [Google] [Yandex] [Bing]
aaaaa.png
83KB, 694x801px
>>51880793
Here. For your efforts.
>>
>>51881029
It should work with
a = b = math.pow(2, sizeof(int)*8-2)
>>
How to average a varying amount of integers in C?
>>
>>51881037
>long
no, ints.
>>
>>51881029
All of them. Do not come back until you have tested your code on all combinations of two integers.
>>
>>51881037
I've counted five weeks. I guess we could find the real number if we consult the archives.
>>
>>51881066
In the real world one would just use GMP, a library for arbitrary precision arithmetic.
>>
>>51880811
kill yourself
>>
>>51881071
for (int a = INT_MIN; a <= INT_MAX; ++a)
{
for (int b = INT_MIN; b <= INT_MAX; ++b)
{
avg(a, b);
}
}


It works, done
>>
>>51880953
A U T I S M
U
T
I
S
M
>>
>>51881029
>test cases
you don't prove it correct with test cases, you web nut, you prove it correct with reasoning and knowledge of the standard
>>
>>51881087
>In the real world one would just use GMP, a library for arbitrary precision arithmetic.
No, you wouldn't. Because
1) GMP is deprecated, you should use GNU MPFR instead
2) Including a fucking third party library for calculating the average of two ints is Webdev-tier. Go back to your jQuery and angular.js
>>
Can anyone help me? It boggles my mind at what the book really wants from me:

7. Show how a short-circuit AND can be used to prevent a divide-by-zero.

Do I code it?
Or do I just describe an example doing it?

I know that I can show it similarly like the 1 0 bit operation or a logical true false sentence...

Let 1 be T for True and 0 be F for false:

T F T ^ F
--------------
T F F
F T F
F F F
T T T
>>
>>51880974
int average2(int a, int b) {
return (a >> 1) + (b >> 1) + (a & b & 0x1);
}

int average3(int a, int b, int c) {
return average2(average2(a, b), c));
}
>>
>>51881117
>units tests are only for web
you're embarrassing yourself now
>>
>>51881108
>it is autism to point out that the average of 4 and 5 is actually 4.5
How did you people even pass high school?
>>
>>51881117
I think TDD somehow seems to attract the biggest retards in all of programing. There are some who seems to think you can't know any piece of code is correct until you write some kind of shitty unit test for it, which is probably more likely to contain bugs than the code it's testing.
>>
>>51881134
>thinks he can prove C code to be correct with test cases
anon, you might as well return to /wdg/
>>
>>51881127
>calculating the average of two ints

>reading comprehension
The question was about averaging an ARBITRARY NUMBER of ints, which you are unable to do in C, I'm 100% sure.
>>
>>51881136
>/dpt/ - Daily Programming Thread
>ints, not integers, not real numbers, I N T S
kill yourself
>>
>>51881133
that average2 doesn't work.
avg(-6, -7) should return -6
>>
File: programming-goto-guy.jpg (14KB, 250x250px) Image search: [Google] [Yandex] [Bing]
programming-goto-guy.jpg
14KB, 250x250px
>>51881117
Actually, you prove it correct with mathematical proofs.

Pic related
>>
>>51881136
It's autism to point it out when the problem explicitly states answer should be an integer.
>>
>>51881134
no, unit tests are only for good programmers to use. Not ones who think you need to unit test basic programming logic.
>>
File: iE55839.jpg (107KB, 700x1243px) Image search: [Google] [Yandex] [Bing]
iE55839.jpg
107KB, 700x1243px
>>51881029
something like this plus some special cases (int_max and int_min)
for (int i = 0; i < INT_MAX; ++i)
{
for (int j = 0; i < INT_MAX; ++i)
{
assert( average(i, j) == ((int64_t)i + j) / 2 );
assert( average(i, -j) == ((int64_t)i + -j) / 2 );
assert( average(-i, -j) == ((int64_t)-i + -j) / 2 );
}
}
>>
>>51881145
No, you can do it with va_list as long as the user also passes how many integers they are passing as an argument.
>>
>>51881153
no, mine rounds down. this is the intended behavior.
>>
>>51881141
this. TDD fags are even more retarded than FP fags
>>
>>51881185
FP is great. Pure FP is however retarded, just like shitty TDD, as most of it seems to be.
>>
>>51881170
>No
No. You were wrong.
Anyway, passing the ints is not the problem. Averaging N ints correctly is the problem and so far I'm inclined to believe that /g/ is unable to do it.
>>
>>51881150
>>51881145
>The question was about averaging an ARBITRARY NUMBER of ints
In that case, use stdarg.

>>51881150
You know that real representations exist too. The average of two ints is not an int.

Are you some kind a retard who defines PI as 3?
>>
>>51881144
No one's trying to prove anything correct.

>>51881164
It's not as simple when you don't have access to larger size long or double floating point units, and having test cases might also help discover bugs in weird compilers.
>>
>>51881184
operations on ints truncate unless specificied otherwise
>>
>>51881160
>look ma', I posted something
fuck off
>>
>>51881132
Code it and explain why the short circuiting prevents it. You can't show it using truth tables, short-circuit logic works by only partially evaluating the truth table.
>>
>>51881198
>In that case, use stdarg.
lol, passing the ints to a function is not the problem. Averaging N ints correctly without overflow and with proper rounding is, and /g/ is unable to solve it.
>>
>>51881150
>doesn't know that both float and double exist as real representations

>>51881162
>It's autism to point it out when the problem explicitly states answer should be an integer.
It doesn't, it simply states:
>How do you calculate the average of two ints [in C]?
The average of two ints is not an int.
>>
>>51881197
Use 8 byte float to calculate sum and then divide by count :^)
>>
>>51881133
The average of three numbers is not the average of the average of a and b, and c.
>>
>>51881198
>The average of two ints is not an int.
so why does this work in a strongly typed language:
int a = 1;
int b = 2;
int average = (a + b) / 2;


KILL YOURSELF
>>
>>51881199
>No one's trying to prove
not you, anyway, since you're a fucking retard
>>
>>51881213
So you're not autistic, just uninformed. Good for you.
>>
>>51881231
Average will be 1, not 1.5
>>
>>51881212
>Averaging N ints correctly without overflow and with proper rounding is, and /g/ is unable to solve it.
It isn't complicated. Why on earth would you include a FUCKING library to do so?

Go back to jQuery
>>
>>51881213
>in C
>average of two ints is not an int
m8...
>>
>>51881234
?
>>
>>51881213
you legit have autism m8

>average two ints in C
there is not enough information to infer that it should be a float or a double.
>>
File: Capture.jpg (75KB, 887x401px) Image search: [Google] [Yandex] [Bing]
Capture.jpg
75KB, 887x401px
Im trying to make this thing print random images, different colored cars, and im not sure what im doing.

public FroggerComponent(String filename)
{
setPreferredSize(new Dimension(WIDTH*PIXELS,HEIGHT*PIXELS));
readRow(filename);

String[] images = new String[]{"0.png","1.png","2.png","3.png","4.png","5.png"};
JLabel MyImage = new JLabel(new ImageIcon(
images[(int)Math.floor(Math.random()*images.length)]));

frog = readImage("Images/frog.png");
lily = readImage("Images/lily.png");
car = readImage(MyImage);
readRow("Images/world.txt");
reset();
}
>>
>>51881231
>calling the variable average makes it the average

>>51881235
>So you're not autistic, just uninformed. Good for you.
Nice deflection, where does it state that the answer needs to be an int?
>>
>>51881240
which is 100% accurate within the precision of ints.
>>
>>51881257
In original problem, the one we're talking about. It's not in this thread, before you ask.
>>
>>51881257
>where does it state
>I only know js
>everything should be double
came all the way here from /wdg/?
>>
When is this average shit gonna die off?
For the last 3 or 4 days it's been absolute garbage. More so than it usually is.
With the trapfaggotry, anime arguing, language shilling, and general forced-meme faggotry, reading this thread is completely painful.

Can someone just post what they're working on? Or can someone start a group project? I can make the logo :^)
>>
>>51881257
KILL YOURSELF

YOU ARE EVEN MORE AUTISTIC THAN I AM

FUCKING KILL YOURSELF MY MAN
>>
>>51881248
>there is not enough information to infer that it should be a float or a double.
Yes there fucking is

>average
As
In
Fucking
Arithmetic
Mean

How autistic are you to believe that since the input is two ints then the answer MUST be an int?

Rule of thumb: Read the question before answering.

>>51881243
See above
>>
>>51881276
It will end when someone successfully does it
>>
>>51881276
>When
when you get it right or gtfo, webcá Žuck
>>
>>51881290
K I L L Y O U R S E L F
I á Ž I
L á Ž á Ž á Ž L
L á Ž á Ž á Ž á Ž á Ž á Ž L
Y á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž Y
O á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž O
U á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž U
R á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž R
S á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž S
E á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž E
L á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž L
F á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž á Ž F
>>
>>51881291
No it won't. Shut the fuck up.

>>51881296
Hey, "big dick playa" faggot. Go off yourself.
>>
>>51881291
We have you dumb fuck.
>>
>>51881271
>In original problem, the one we're talking about.
Post the original problem then...

>>51881275
Go back to /wdg/
>>
How do I regex in C?
emailvalidation.c:43:29: warning: unknown escape sequence: '\w'
status = regcomp(&regex, "\w.*\@\w*\.\w*", 0);
^
emailvalidation.c:43:29: warning: unknown escape sequence: '\@'
emailvalidation.c:43:29: warning: unknown escape sequence: '\w'
emailvalidation.c:43:29: warning: unknown escape sequence: '\.'
emailvalidation.c:43:29: warning: unknown escape sequence: '\w'
>>
>>51881241
>It isn't complicated.
All talk, no substance.
You're unable to do it.
>>
>>51881275
I'm not the one who includes jquery to calculate the average of two ints in C.
>>
>>51881308
escape the backslashes
>>
>>51881302
>big dick
swinging past yo' kneeeeees!
>>
File: 1422808766386.png (302KB, 1920x1080px) Image search: [Google] [Yandex] [Bing]
1422808766386.png
302KB, 1920x1080px
I like niggers.
>>
>>51881320
Should the average of two ints be the floor or the ceil?
>inb4 a float
>>
>>51881330
Fuck off back to highschool, this is an 18+ site.
>>
>>51881307
In C, calculate an integer average of two integers.
>>
>>51881308
You need to escape those \'s man.
>>
>>51881341
>my ass still hurts from the previous threads
then go back to your html tutorials
>>
>>51881340
It should be correct arithmetic rounding.
floor for [0 ... 0.5[
ceil for [0.5 ... 1[
>>
>>51881346
>>51881329
ok, now my program is telling me that regcomp returned a non-zero value because it didn't like my regex.
>>
File: 1400603790863.png (110KB, 344x278px) Image search: [Google] [Yandex] [Bing]
1400603790863.png
110KB, 344x278px
>>51881337
>mfw I rolled fuckin 1337

PS: what is a fuckin website generator? how do I have to understand that shit?
>>
>>51881340
truncate, i.e. round toward zero
>>
>>51881340
Should be consistent and explicitly specified which it is. Either is fine.
>>
>>51881340
>Should the average of two ints be the floor or the ceil?
No, it should be a real number.

>hurr durr doubles are wasteful because muh javascript uses doubles
>herp derp use GMP instead

How autistic is that? Avoiding doubles for all cost...
>>
>>51881341
>18+ site
You're wrong. You want to get told again and make a buffoon of yourself?
Please, anon, don't b8 the big dick playa again; you know he'll just destroy your ass.
>>
>>51881359
That's literally your only ammunition. Ever.
>hurr i have a big dick
>hurr go back to webdev im a fuckin tool whos 16 years old
You sure are.
>>
>>51881344
When was this the original?

If you search the archives, you'll see that the original is calculate the average of two ints in C.
>>
>>51881360
you are seriously 100% autistic i swear

there is no one "correct" way to do aithmetic rounding. it could be floor for 3.5 and ceil for 4.5 for instance. always rounding up .5 can cause rounding errors to accumulate. retard.
>>
>>51881384
>it should be a real number
this ain't nodejs, webshit!
>>
>>51881384
fuck off to /wdg/ fucking autistic retard
>>
>>51881391
>got told by 16 yo
REKT
E
K
T
>>
>>51881415
>webshit
Says the guy who wants to include fucking jquery to calculate an average

topkek
>>
>python was written in C
>python can average two ints
is it possible for Guido van Rossum to be smarter than /g/?
>>
>>51881391
Dick Envy: The Post
>>
>>51881442
anyone can include a big int library and do it 1000x slower
>>
>>51881428
>hurr durr pi is 3
>herp derp arithmetic mean is not a real number
>HURR DURR HERP DERP USE A DEPRECATED LIBRARY TO CALCULATE THE AVERAGE BECAUSE I CAN'T DO IT MYSELF
>>
>>51880554
jesus christ talk about horrific colors just use VS's default one ffs
>>
>>51881430
>muh doubles
>muh prototype
>muh memejs
fgt...
>>
>>51881458
>HURR DURR RETURN A DOUBLE BECAUSE I CAN'T DO IT WITH INTS LIKE I WAS INSTRUCTED TO
>>
>>51881455
>big int library and do it 1000x slower
So why include GMP?

REKT
E
K
T
>>
File: 1405453964432.jpg (258KB, 660x546px) Image search: [Google] [Yandex] [Bing]
1405453964432.jpg
258KB, 660x546px
>/g/ can't average a varying number of ints in C
>tries to deflect from their incompetence by calling each other webshits
>no working code for averaging N ints in C is posted
>>
>>51881458
>herp in js everything is a real number
>derp why is c so hard
>muh css
kill yourself
>>
File: blindeyeswhitedankn.jpg (9KB, 250x250px) Image search: [Google] [Yandex] [Bing]
blindeyeswhitedankn.jpg
9KB, 250x250px
Prolog error:

Cannot print stack while in 3-th garbage collection
Error: Trapped signal 11 (general protection fault), aborting...

This only happens when I try to find an optimum value via labeling([min(Var)],Var). Otherwise the query runs fine with just label(Var). Anyone know why?
>>
>>51881475
>instructed to
I was instructed to average two ints, not to truncate it. GMP will not return it as int either btw.

REKT
E
K
T

>>51881473
How are doubles webdevtier but somehow including fucking jquery to do it, not? You accomplish the same fucking thing.
>>
>>51881483
c is a dead language.
>>
>>51881488
>muh jquery
>muh html and css solves it for me
go back to /wdg/
>>
>>51881505
>doubles
>webdevtier
confirmed js fag
gtfo to your homescreen thread you useless shit
>>
>>51881363
I'm guessing it means a program or library that will write a static (i.e. just serves file) website when run. Jekyll and Hakyll would be examples
>>
Thread is cancer.
>>
>>51881488
>hurr durr using doubles is webtier
>herp derp using GNU bloatshit to represent arbitrary precision numbers are not
Pythoncluck detected
>>
>>51881510
>what is js
>>
>>51881531
>muh GNU bloatshit jquerytier lib to average two numbers
>>
>>51881554
cá Žuck
u
c
k
>>
I am >>51880793. I am tard, I was doing this all the time when I could just do this. Got it to work:
return (a / 2) + (b / 2) + (a%b%2);
>>
>>51881570
You're just envious of my big C dick
>>
>>51881483
enum {INT_BITS = CHAR_BIT*sizeof(int)};

// depends upon signed integer overflow (undefined behavior)
int avg1(int a, int b)
{
return (((a+b)/2) & ~(1<<(INT_BITS-1))) | (((a/2)+(b/2)) & (1<<(INT_BITS-1)));
}

// avoids signed integer overflow, but has conditional
int avg2(int a, int b)
{
if ((a < 0 && b > 0) || (a > 0 && b < 0))
return (a+b)/2;
else
return a/2 + b/2 + (a%2 + b%2)/2;
}

// avoids signed integer overflow, no conditional either, but most optimizing compilers
// will compile this to a conditional
int avg3(int a, int b)
{
int t = (unsigned)(a^b)>>(INT_BITS-1);
return ((a/2+b/2+(a%2+b%2)/2)*!t) | (t*(((t*a)+b)/2));
}
>>
>>51881546
>I don't know C
>I want muh animu back
>where are muh traps
>how about a watch thread
fuck off
>>
>>51881569
>muh doubles
>what is C
>what is int
>what is efficiency
html all the way, amirite, webshit?
>>
>>51881589
Nice memes

But can you average two ints in C?
>>
File: fc,550x550,white.u1.jpg (19KB, 550x550px) Image search: [Google] [Yandex] [Bing]
fc,550x550,white.u1.jpg
19KB, 550x550px
>>51881588
>avg3
>only 2 arguments
>>
>>51881589
I do know C.
I don't like anime.
I don't like traps.
I don't have a watch.
Kill yourself, you dumb, childish cunt.
>>
>>51881587
>big C dick
>can't average 2 ints
sure thing, csscá Žuck
>>
>>51881617
I wish I was a janitor, I'd do your post for free.
>>
>>51881609
>efficiency
Dude

You're advocating using a fucking GNU bloat library


When using IEEE floating points suffice...

What do you think is the slowest, GNU crossplatform muh FREEEDUMBS boilerplate to avoid wrapping or doing a single floating point div?
>>
>>51881622
>I got told by the big dick C playa
>got rekt all over /g/ for my stupidity
you dare show your face again, web-boy?
>>
if you're all such leet haxxors then why haven't you "raised" the "points" in your bank account yet?
>>
>>51881647
Please get a trip so I never have to see your childish display if inadequacy.
>>
>>51881624
>sure thing, csscá Žuck
ENVIOUS
N
V
I
O
U
S
>>
>>51881611
nigga, I started this meme! I'm the big dick playa
>>
>>51881652
ITT: /g/tards can't hack banks with C.
>>
File: 1415885401040.jpg (21KB, 400x396px) Image search: [Google] [Yandex] [Bing]
1415885401040.jpg
21KB, 400x396px
>>51881652
You mean good boy points?
>>
>>51881664
>>51881661
just filter off anything including "average" and "ints" in the same sentence, and then "big dick playa" "csscuck" "webfag"
>>
>>51881661
>inadequacy
you're feeling a little short? did my big dick precipitate yours into shrinking? back to /wdg/!
>>
>>51881032
>assumes that int is not 64 bit
>>
>>51881665
>I started this cancer! I'm the autistic manchild
ftfy
>>
Jesus fuck this thread is shit.
>>
>>51881700
No kidding.
>>
>>51881645
dude, you're advocating using js and html! fuck off to /wdg/; this is a thread for programmers, not "web developers"; apply yourself, fgt
>>
>>51881694
breaks with
pow(2, sizeof(int)-2)
>>
Guys, I wanted to learn C but now I'm scared about all this "averaging two ints" "impossible" challenge. Can I just ignore it or is it easy shit that should I be able to do tier?
>>
>>51881685
>csscuck
>webfag
Then how will you know when people address you?
>>
>>51881712
>dude, you're advocating using js and html!
I'm not, but I'll take your shitty "memeing" as your admission of defeat. Now please smash the computer over your head and light your shirt on fire.
>>
>>51881697
>I'm intimidated by c AND your big dick
everyone knows that
>>
>>51881715
Uhm, sizeof(int) doesn't give you number of bits...
>>
>>51881700
This is what we get for using a free-to-use anonymous imageboard. Don't expect serious discussion.
>>
>>51881739
>I'm a web developer
>operations on ints should result in doubles
in that case...
>>
>>51881700
>muh animooooooo
>muh feminine penis
>muh crossdressing
yeah, it used to be so much better...
>>
>>51881753
>>I'm intimidated by c AND your big dick
Thank you for admitting that.

>>51881773
>>operations on ints should result in doubles
Many operations on ints results in doubles.

2 + .5; // tell me how this isn't implicitly cast by C to a double
>>
>>51881729
impossible for "web developers"
>>
>>51881788
>.5 is an int
cssfag detected
>>
>>51881788
>Many operations on ints results in doubles
>on ints
>ints
>plural
>shows sum of an int and a double
>proud
anon, html might not be so bad for you
>>
>>51881811
>2 isn't an int literal
webfag pls
>>
r8 my function

static int
grub_username_get (char buf[], unsigned buf_size)
{
unsigned cur_len = 0;
int key;

while (1)
{
key = grub_getkey ();
if (key == '\n' || key == '\r')
break;

if (key == '\e')
{
cur_len = 0;
break;
}

if (key == '\b')
{
cur_len--;
grub_printf ("\b");
continue;
}

if (!grub_isprint (key))
continue;

if (cur_len + 2 < buf_size)
{
buf[cur_len++] = key;
grub_printf ("%c", key);
}
}

grub_memset( buf + cur_len, 0, buf_size - cur_len);

grub_xputs ("\n");
grub_refresh ();

return (key != '\e');
}
>>
>>51881822
>.5 is an int literal
you can't seriously be this retarded
>>
>>51880381
Can someone link me to the best possible explanation of MVC vs MVVM vs MVP?
Especially one with some examples.
>>
>>51881825

It's a function.
>>
>>51881820
>shows sum of an int and a double
No, I didn't.

I showed an expression with an int and a double, not the sum.

Are you autistic or something?
>>
>>51881825
0/10 can't even average one int
>>
>>51881788
>I'm intimidated by c AND your big dick
we know
>operations on ints results in doubles
that's why you're stuck on bottom of the barrel "html programming"
>>
>>51881843
>webfag gets told
>average 2 ints memer gets RAPED
R E K T
E
K
T
>>
>>51881843
>I showed an expression with an int and a double, not the sum.
>Are you autistic or something?
Said without a hint of irony
>>
>>51881833
You can't seriously be samefagging this hard.

>implying I said it was
>strawmanning this hard because you don't even have a point
>hue hue hue a function that takes two ints MUST return an int because I have severe autism
>>
>>51881843
>+
>not sum
this ain't js, htmlfag, + is addition in C and evaluates to the sum of the operands
at least know the fucking basics before opening your fuckhole
>>
>>51881858
>Said without a hint of irony
>Said
>on an online image board for taiwanese tapestry
It's like you're not even trying.
>>
>>51881861
>huehue
>1+2 is not an int
wtf are you smoking, pajeet?
>>
>>51881877
>>51881843
get rekt by the real big dick playas that don't care about your shitty meme challenges
>>
>>51881877
You don't know C if you don't even know what an expression is.

Read the standard, webfag.
>>
>>51881895
>I don't know C
this is obvious
>>
>>51881885
>+ operand
>function
What are you smoking?
>>
>>51881895
still mad for getting your ass stretched yesterday? no worry, the big dick playa does it all the time; you'll get used to it (unless you run back to your desktop thread)
>>
>>51881911
>backpedaling
Suck my C dick, or is it too big for you?
>>
>>51881913
>cá Žucked by w3c
m8
>>
>>51881921
>yesterday
What? I wasn't even lurking /g/ yesterday. Schizo much?
>>
>>51881943
>pretending
>animoo
>chink
>traps
ishyggy
>>
"big dick C playa" just got rekt by the standard

noise
>>
>>51881922
>i want a big dick
swinging past yo' kneeeeees!
>>
>>51881966
>where muh animu traps at?
stand down, jamal
>>
>>51881206
Thank you.
>>
Hey, guise, is it hard to average 2 int variables in C? /wdg/ says it's impossible. Is it true, /g/? Can you do anything else beyond memeing fizzbuzz all day long?
Tell me, gee!
>>
Can we turn this thread into /dog petting thread/ yet?
>>
Anyone tried compiling C++ in B&R automation studio? Even an empty program in a new project can't compile.
c:/brautomation/as41/as/gnuinst/v4.1.2/bin/../lib/gcc/i386-elf/4.1.2/../../../../i386-elf/lib\libbur_cpp.a : In function `allocModuleMemory'
bur_cpp.c (.text+0x53d) : Error : undefined reference to `bur_heap_size'
bur_cpp.c (.text+0x545) : Error : undefined reference to `bur_heap_size'
bur_cpp.c (.text+0x562) : Error : undefined reference to `bur_heap_size'
bur_cpp.c (.text+0x5b9) : Error : undefined reference to `bur_heap_size'
c:/brautomation/as41/as/gnuinst/v4.1.2/bin/../lib/gcc/i386-elf/4.1.2/../../../../i386-elf/lib\libbur_cpp.a : Error : bur_cpp.c:(.text+0x5ce): more undefined references to `bur_heap_size' follow

Automation studio 4.1.9, gcc 4.1.2 with default flags
>>
>>51882031
no because cats are objectively better than dogs
>>
>>51882014
a/2+b/2+(a%b%2)
>>
>>51882032
check the library flags you tard
>>
>>51882014
>/wdg/ says it's impossible. Is it true, /g/?
/wdg/ is on /g/.
The meme you used is old.
>gee!
C-. You are going to have to try harder if you want to pass Introduction to Bait and do JKS213: Dank Memes.
>>
>>51882038
Cats are evil hellspawns that will claw your eyes out for the hell of it with no warnings or reason

Dogs are man's best friend

>>51882032
Are you sure it's trying to link it as C++ and not C?
>>
>>51882070
>old
I just invented it last week, anon.
>>
>>51882070
>Introduction to Bait
seems to be doing bretty gud: you fell for it
>>
>>51882110
>last week
That's like forty years ago in internet time
>>
file i/o using asynctask on an android application

just finishing it up here
>>
>>51882126
Then I'll come back tomorrow with a new one. We need to keep this thread fresh!
>>
>>51882143
webcuck

webcucks everywhere
>>
>>51882160
wat

are you calling me a web developer
>>
>>51882170
>can't even average two ints in C
>C is hard
>muh js and js.io and async meme.js
>>
>>51882147
finally. now I can rest in peace knowing I can average two ints.
>>
>>51882197
dude this post is the first time i posted in this thread:

>>51882143

maybe i should just leave
>>
>>51882206
Just don't respond to them. Making everyone leave is their goal.
>>
>>51882206
>leaves in shame because he can't average two ints
I wish more csscucks here followed your example, so we could improve these threads
>>
>>51882216
Do I need to know how to average two ints to be a good C-grammer?
>>
>>51882082
So far I didn't even change anything, it's the default configuration made by b&r. I'm clueless.
But hey, at least I can get C to compile with -std=gnu99
>>
>>51882253
Well, it looks like those linker issues you get when you try to link C++ compiled code as not-C++.
>>
>>51881337

lets see
>>
why can't someone fuck with the desktop shitters they actually deserve it
>>
import average
...
print(average(x,y))
>>
>>51882293
What did they do to you?
>>
>>51881588
try this

int avg2(int x, int y) {
int sum = (x / 2) + (y / 2);
int mod = (x % 2) + (y % 2);
sum -= (sum > 0) * (mod == -1);
sum += (sum < 0) * (mod == 1);
return sum + mod/2;
}

int avg1(int x, int y) {
int sum = (x / 2) + (y / 2);
int mod = (x % 2) + (y % 2);
int nsig = (sum < 0) - (sum > 0);
return sum + nsig * (nsig == mod) + mod / 2;
}
>>
>>51881337
Rolling for bored af
>>
>>51882227
okay faggot

so anyway i'm getting the hang of AsyncTask<Void, Void, String> for file i/o from internal storage and such. i'm worried about using intents for this because of how the threading works

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == PAYMENT_REQUEST) {
...
>>
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == PAYMENT_REQUEST) {
...
>>
>>51882335
Calculate the average of two ints in C
>>
>>51882355
>>51882343
what the fuck are you doing?
>>
>>51882391
trying to paste code

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == PAYMENT_REQUEST) {
...
>>
>>51882412
read the sticky my man
>>
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == PAYMENT_REQUEST) {
...
>>
>>51882451
OH FUCKING HELL
>>
File: my-sides.gif (2MB, 400x398px) Image search: [Google] [Yandex] [Bing]
my-sides.gif
2MB, 400x398px
>>51882470
>>51882451
>>51882412
>>51882355
>>51882343
My sides
>>
>>51882451
>>51882470
keeek
>>
>>51882361
char[8] a = "faggots";
char[8] b = "no life";
int avg;

avg = (a + b);

printf("\nThis leads to %s.\n", avg)




Output is: "This leads to shitposting endlessly about meaningless crap instead of coding or doing anything productive because they are dead inside and they hate themselves."

Crazy right?
>>
File: reeeeeeee.png (10KB, 527x347px) Image search: [Google] [Yandex] [Bing]
reeeeeeee.png
10KB, 527x347px
What am I doing wrong that it won't let me create a variable of type index?
#include <stdio.h>
#include <stdlib.h>
#define MAX_RECORD 50
int main(int argc, char* argv[])
{
struct index{
char name;
char street;
char cityST;
char zipchar;
long ziplong;
};
index *record = (index)malloc(MAX_NAMES*index);

return 0;
}
>>
new thread when ? :3
>>
>>51882586
do you mean sizeof(index)?
>>
>>51882586
index *record = (*index)malloc(MAX_NAMES*sizeof(index));
>>
Guys, I couldn't average two ints without asking to someone. Do I stop programming?
>>
>>51882621
You stop taking the bait and let this fuckin' idiotic meme die.
>>
File: Untitled.png (12KB, 594x368px) Image search: [Google] [Yandex] [Bing]
Untitled.png
12KB, 594x368px
>>51882606
>>51882614
Whoops. Yeah, I had it written like that previously but I was shitting around with it to try and get it to work. Still doesn't work like that.

Won't even work like this. It was working fine before, but I started trying to make separate files and I think the IDE sperged out.
>>
File: asdf.png (49KB, 922x884px) Image search: [Google] [Yandex] [Bing]
asdf.png
49KB, 922x884px
what am i doing wrong here for it to not be sorting the numbers in order, and only reading the last number?
>>
>>51882664
If your typedef for index is in another file you need to #include<index.h> or whatever.
>>
>>51882639
Thanks anon, I understand how the algorithm to average two numbers works now and I'll continue learning.
>>
>>51882594
310 as always. Don't be a faggot like that faggot anon. If he tries to post early simply post another one at the right time and we'll all move to you're's.
>>
>>51882528
>avg = (a + b);
spotted the web "developer"
quick, add some testcases!
>>
>>51882667
There's a bad parenthesis on line 43.
>>
>>51882664
First off, it should be "index*" not "*index".

Secondly, it's at least not good form to declare the structure inside main like this. It should be declared outside of main.

Thirdly, I'm assuming this is C++ and not C, so you're using a C++ compiler to compile it, right? It won't compile with a C compiler.
>>
>>51882762
Oooh, what a naughty little paren. Came way too soon.
>>
>>51882711
>310 as always.
it's 300
>>
>>51882782
/wdg/ everyone
>>
>>51882762
what's wrong with it? it looks fine to me
>>
>>51880381
at the moment I'm just trying to coordinate a clusterfuck between a vendor application, my application, and our off shore security consultant.

Enterprise IT fuck yer.
>>
>>51882711
>If he tries to post early simply post another one at the right time and we'll all move to you're's.
yeah right
>>
The /wdg/ Web Development General thread
>>51827781 has their own IRC channel:
#/g/wdg on irc.rizon.net
Shouldnt /dpt/ start using #/g/sicp which currently has 160 members?
>>
>>51882803
printf("%s\n", nums[ctr]);
>>
>be me
>want to be computer engineer
>go into an intro to c++ 8 week course
>struggle with the challenge problems
>realize I may not be cutout for this

what should I do, /dpt/?
>>
>>51882821
get a burger flipping job
>>
>>51882812
Everytime but one I've counter-posted to that faggot, mine became the main thread.
>>
>>51882818
%d i mean
>>
>>51882821
give it more time and effort

read other resources outside of the class
>>
>>51882664
It's been a long while since the last time I've compiled anything on windows, but are you sure you need to cast the pointer returned by malloc?
>>
File: legit.png (28KB, 1192x428px) Image search: [Google] [Yandex] [Bing]
legit.png
28KB, 1192x428px
>>51882818
???
>>
>>51882735
ok faggot
post your solution and prove it works
oh right you cant, it doesn't exist
>>
>>51882843
You never need to cast malloc.
>>
>>51882849
Look up the fucking syntax for printf
>>
>>51882836
it can work but it failed last time

see the deleted posts in >>51874414

my thread was deleted and i got blocked from posting for 15 mins
>>
>>51882849
cmon dude...
printf("%d\n", nums[ctr]);
>>
hey guise, should I learn C or C++?
>>
>>51882839
thank you so much. that god damn parenthesis. it works now, i added it to the end XD
>>
NEW THREAD

>>51882877
>>
>>51882875
heheh, orly. try try again.

>t. survivor of pony wars. we outlasted moot lol.

>>51882880
Sepples.
>>
>>51882821
realize that while its admirable to try, you will never be the best. In reality you're going to be average, and that is fine. There are still plenty of jobs out there for the C students, you're not going to be working at google, but you will make a good living (until you get outsourced).
>>
>>51882821
Work harder on side projects and ask for help whenever you need it.

>>51882860
That's what I thought.
>>
>>51882763
1) Okay
2)I don't know whether my professor would take off points for doing it like that, considering the examples he showed were inside of main but I'll keep it in mind for the future.
3)It's supposed to be C

>>51882843
The professor said it needs to be cast, so to err on the safe side I'll just do it.
>>
LEGIT NEW THREAD WITH NO TRAP FAG OP AND POSTED AFTER THE BUMP LIMIT

>>51882900
>>51882900
>>51882900
>>
>>51882911
already made, knock this retardism off.
I swear you're all a bunch of fucking manchilds.
>>
>>51882906
Man, your professor is terrible. Do as he said during the evaluations but follow good coding practices for everything else.
>>
>>51882821
>8 week course

That's your problem. After this 8 week course, re-read the chapters at a slower pace. A good programmer is one that continuously hones their craft. Nobody becomes a good programmer in 8 weeks.
>>
>>51882931
fuck off nigger faggot
>>
>>51880911
>+ 0.5;

That doesn't work on negative numbers. Rounding goes away from zero.
>>
>>51881168

Your inputs are moving in lockstep. Well, actually they aren't, because you wrote ++i the second time, so j never changes.

It's probably much better to do testing on randomly generated input over a large number of iterations.
>>
>>51882324
Mine already work dummy.
>>
>>51882586

No idea if you were corrected yet, but you need to cast to index*, not to index.

index *record = (index *)
Thread replies: 323
Thread images: 22
[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