[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: 21
File: 0131315099.jpg (71 KB, 480x648) Image search: [Google]
0131315099.jpg
71 KB, 480x648
C and Unix edition

old thread
>>51996984
>>
The C deprecated language.
Now with extra memory leaks and segfaults.
>>
File: scala-logo.gif (16 KB, 635x282) Image search: [Google]
scala-logo.gif
16 KB, 635x282
nth for Scala
>>
File: 20151222_175647.jpg (1014 KB, 2048x1152) Image search: [Google]
20151222_175647.jpg
1014 KB, 2048x1152
What do you think about my networked, public-key encrypted Hello World in Go?

Took a few hours since I had never done anything in Go before
>>
>>52002043
>photo of screen
no
>>
>>52002023
C doesn't have those features. Bad programmers with Java backgrounds do.

>>52002051
I didn't have my ThinkPad connected to the web
>>
damn, a little late to party

>>52000981

brainfuck solution

>,[>++++++++++[->++++++++++<]>[->+>
+>+>+>+<<<<<]>--->+>+++++>>>++++[-<
++++<+++>>]<+<-<<<<<<[->>>->->->->-
<<<<<<<]>+>++++>[[-]<->]>[[-]<<->>]
>[[-]<<<->>>]>[[-]<<<<->>>>]>[[-]<<
<<<->>>>>]<<<<<[[-]<->]<[-<<+>>]<,]
++++++++++<[->-[>+>>]>[+[-<+>]>+>>]
<<<<<]>>>[->+>+<<]++++++++++++[-<++
++>>++++<]>>[[-]<.>]<<<.
>>
IDE/editor poll:


https://strawpoll.me/6339288
>>
>>52002043
>photo of screen
no
>>
>>52002061
void *ayy = malloc(sizeof(int));
ayy = malloc(sizeof(char));
>>
>>52002066
nice, i never got deeper in bf than basic input output
>>
>>52002105
It is all blonde, brunette and redhead after a while
>>
>>52002174
huh?
>>
>People don't know that 'y' can sometimes be a vowel.
>>
>>52002073
I didn't have my ThinkPad connected to the web
>>
File: Fm6HWGJ.png (183 KB, 480x529) Image search: [Google]
Fm6HWGJ.png
183 KB, 480x529
Winner of previous code golf is
>>52001682
with
p gets.count "aAeEiIoOuU"


New golf:
Count the number of elements in a list of integers that belong to the fibonacci sequence.

First integer in the input is the size of the list, and the rest of the input is the list itself.

Example:
input: 4 1 3 29 7
output: 2

input
>>
>>52002092
Found the java programmer
>>
>>52002293
from fibonaccitools import fibonaccitest
n=0
for e in a:
if fibonaccitest(e):
n+=1
>>
>>52002293
dude, you are really making this hard for brainfuck
>>
>>52002324
what's a
>>
File: python-logo.jpg (8 KB, 426x284) Image search: [Google]
python-logo.jpg
8 KB, 426x284
This is how I safe a file from the Internet in python
Is it ok, or is there a better way?

import urllib.request as req

url = 'http://weather.yahooapis.com/forecastrss?w=796597&u=c'

with req.urlopen(url) as response, open('test5', 'wb') as out_file:
data = response.read()
out_file.write(data)
>>
File: 20151220_172459.webm (3 MB, 720x405) Image search: [Google]
20151220_172459.webm
3 MB, 720x405
Meme sign guy here once more. I decided that sending and receiving strings over UDP was fun, but not really useful other than getting a lot of variations of 8===D~~ sent to me by other people on /g/.

I found a library that interfaces with 4chan for python that I used to make a windows service which streams new posts from the roguelike general in /vg/ as they appear. The service starts up and stops properly with computer startup/shutdown. One thing that I'm not too happy with is how I track the (approximate) last post that was displayed on the sign. I'm currently saving its post ID to a text file and reading that on startup, writing to it if the new post is 3000 or so greater than what was saved in the file. I don't know where shit like that would normally be stored for a proper service.

If any of you autists want to do something similar here are the (shitty) source files.

https://github.com/JLipinski/4chanGeneralTicker

Remember to like and subscribe to my blog :^)
>>
>>52002293
sml@"aeiou"drzZ


do you niggers even codegolf?
>>
>>52002439

curl http://random.website.com/ayyy/lmao
>>
>>52002560
and?

and are you just retarded and you actually meant
curl -s "http://random.website.com/ayyy/lmao" -o ~/ayyy_lmao.xml
>>
>>52002439
use requests you dingus

site = reguests.get('http://whatever.com')
fp = open('file')
fp.write(site.content)
>>
>>52002611
I would like to stick to the standard library of python3
>>
>>52002676
why in the hell would you do that
the one reason to use python is for the libraries
>>
>>52002696
>>52002611
>missing 'w'
>writing bytes, needs string
try again
>>
>>52002293
def t(n)a,b=0,1;while b<n do a,b=b,a+b end;n==b;end
p gets.split.count{|n|t n.to_i}

dunno
>>
File: 15 - 1.png (303 KB, 405x692) Image search: [Google]
15 - 1.png
303 KB, 405x692
friends please help, I cannot see where I am going wrong here

I'm using http://basc-py4chan.readthedocs.org/en/latest/library/board.html

I want to add the board title to a list of all of the boards I can already print(It just prints /g/, /a/ etc). I want to add -Technology, -Anime to that.

I'm calling the title function of the basc_py4chan module but keep getting the error
Traceback (most recent call last):
File ".\basc.py", line 11, in <module>
board_title = board.title()
TypeError: 'unicode' object is not callable


Here's what I'm using to try get the title
board = basc_py4chan.Board('g')
board_title = board.title()


I don't get what I'm doing wrong here :(
>>
>cannot use cPath (type *C.char) as type *C.char_t in argument to _Cfunc_new_aubio_source
REEEEEEEEEEEEEEEEEE
Now I have to figure out how to deal with typedefs.
>>
>>52002760
waaaah
>>
someone unban me from /pol/
>>
>>52002990
board.title is a string(object) not a function
>>
>>52002990
>
board_title = board.title

Why
>>
>>52002990
Why on earth you would use a library to work with the json api. Its takes literally 5 lines to download and parse the json api
>>
>>52003099
Because I am unbearably new
>>
>>52002069
>no acme
you fucked up
>>
>>52003124
So then why not take the time to learn something and do it yourself
>>
>>52003029
Got it, thanks blood
>>
>>52002990

what the fuck are you doing senpai, you don't need to put board.title into board_title, just access board.title

https://docs.python.org/3.5/tutorial/classes.html#class-objects
>>
>>52003132
>other
>>
>>52002034
Why use Scala when you can use Clojure?
>>
>>52002990
Fuck >>52003051 and >>52003162
Here's how you code for real
board_title = board.title
boardtitle = board_title
boardTitle = boardtitle
BoardTitle = boardTitle
>>
>>52001995
nasm:
org 0x7c00

how do you set the code segment directive in gnu c?
>>
>>52003029
>>52003029
You just helped a man rob 2 families...

I hope you can live with yourself.
>>
File: 221515-2216.png (525 KB, 4000x2560) Image search: [Google]
221515-2216.png
525 KB, 4000x2560
Been very lazy with finishing of this keygen... Got valid serials, just activation code generation left
>>
Do people use bitfields regularly in applications programming or is it purely an embedded thing for low-memory environments?
>>
>>52003896
Embedded and realtime only.
>>
I need to take a series of numbers and try all possible combinations of them multiplied or added to each other.
Brute force is accepted. C++.

Is it possible to assemble a string, and then parse it as an instruction?
recursively assemble 1+2+3+4+5+6, then do the math to test the result;
Then 1+2+3+4+5*6
then 1+2+3+4*5+6
then 1+2+3+4*5*6
etc
>>
>>52003896
It's not uncommon to see them as a way to pass options to a function.
It's a much nicer way than passing a fuckload of booleans as arguments.
>>
>>52003896
we do at work, if it is in a class that is instantiated a lot. it is a video game so that happens quite a while
>>
>>52003979
It is not possible without writing an interpreter in C++
>>
>>52003979
Why do you want a string?
>>
>>52003979
Of course it's fucking possible, but it's by far not the best solution. Just have an array of booleans 1 smaller than the input array, generate all the possible permutations, and go through it with those.
>>
>>52004050
I need to be able to pass it in in all possible configurations.
1, 2, 3, 4, 5, 6
12, 3, 4, 5, 6
123, 4, 5, 6
1, 23, 4, 5, 6
etc.

And I'm kind of clueless and assume a string would be the easiest to manipulate like that, and in insert * or + between elements via recursive calls.
>>
>>52003979
don't waste time doing it as strings and parsing them, that's retarded
why does it have to be recursive either jesus christ lmao
>>
>>52004097
Skip the string and do something like (first element + recursive call on rest, first element * recursive call on rest) and flatten that.

That is assuming you don't need multiplication to have precedence over addition.

Either way, there's little point in using a string. Any sort of list should do.
>>
>>52003216
>Dynamic typing
BWAAAAHAHAHAHAA
>>
Is there a name for type systems that do not require you to define your variables at all? It is like inferred typing but without using keywords like "var"

I mean the one in python you can just write t = 5 for example without defining t
>>
>>52004212
Thank you.
>>
>>52004232
See >>52004228

Also you're defining t by saying "t = 5", you just not declaring it/annotating it with a type.
>>
>>52004232
why would you want that?
>>
>>52003979
Are they kept in order, or can the digits be multiplied against non-neighboring digits; and does it include subsets?
>>
>>52004232
>>52004269
Oh, and duck typing is one facet of not having to declare variables, you just assign to them. But it's not duck typing all the time, for example with local variables of a function.
>>
Best type system poll:

https://strawpoll.me/6341002
>>
>>52004279
Kept in order.
1+2+3
12+3
12*3
1+23
No subsets; must use all digits.
>>
What is the easiest way to compile a program so it will run on windows?
I have not much experience with moving applications. I write in C++.
>>
Finally got something working in cgo.
package aubio

// #cgo LDFLAGS: -laubio
// #include <aubio/aubio.h>
// #include <stdlib.h>
import "C"

import (
"unsafe"
"fmt"
)

type Source struct {
d *C.aubio_source_t
}

func NewSource(path string, hopSize uint) *Source {
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))

acpath := (*C.char_t)(unsafe.Pointer(cpath))
ahopSize := C.uint_t(hopSize)

d := C.new_aubio_source(acpath, 0, ahopSize)
fmt.Printf("%v", d)

return &Source{
d: d,
}
}

func (s *Source) Close() {
C.del_aubio_source(s.d)
}
>>
>>52004316
with a compiler
>>
I'm probably being a dumbfuck, but I'm tired.

In C#/WPF how do I access
public MediaPlayer mediaPlayer = new MediaPlayer();
from my MainWindow in a usercontrol?

I'm not sure how I access it...
>>
>>52004285
I don't think it's a special kind of typing not not use a var keyword. It's just syntactic sugar. The first time you write "t = 1", that's your variable declaration. Most languages use a var keyword because it helps catch more bugs at compile time.
>>
def fib(n)
return 1 if n <=1
fib(n-1) + fib(n-2)
end


how'd I do, boys
>>
>>52004344

Compilers are shit. By-hand translation is the one true method.
>>
File: 1387760791507.jpg (100 KB, 431x432) Image search: [Google]
1387760791507.jpg
100 KB, 431x432
/g/ can't average 3 ints in C
>>
>>52004407
with
var myUserControl = new MyUserControl()
myUserControl.mediaPlayer.play()
>>
>>52004418
Duck typing (which Python has) kind of falls into it, since you can simply add a new field to an object at any time by assigning it.
>>
>>52004433
bad
>>
>>52004433
>return at the top
gosh ruby is so inconvenient, does it do it differently just for the fuck of being different?
>>
>>52004418
most languages (worth using) use a var keyword because they're more complex than some interpreted language, and it's harder for the compiler to tell what's going on
>>
File: bglisp.jpg (42 KB, 500x225) Image search: [Google]
bglisp.jpg
42 KB, 500x225
>>52004433
>>
>>52004450
we're talking about variables, not fields.
>>
>>52004443
(a + b + c) / 3;
>>
>>52004459
basically what I said
>>
>>52004444
That doesn't make much sense.

I've got a button click event in my usercontrol, but I want to access the "mediaPlayer" in my MainWindow, in that button click event.
>>
>>52004475
Fails with
a = MAX_INT
b = 1
c = 0
>>
>>52004443

avg(a, avg(b, c));
>>
>>52003979
The only obvious solution I can think of is to both add and multiply all the time.

Eg.

(X1 + 1*sum) + (X1 * 0 * sum)
Would be the same as
X1 + sum
Or X1 * sum if the 1 and 0 where switched.

Then make a class with a vector of numbers and a bit vector you can manipulate in the for loop.
>>
>>52002455
What's the IP and port so I can send you dicks senpai? :3
>>
>>52004475
C haters BTFO
>>
File: icon175x175.png (29 KB, 175x175) Image search: [Google]
icon175x175.png
29 KB, 175x175
>>52004491
>>
>>52004494

No longer runs the UDP serfer baka. If you want to send me dicks you can go shitpost some in /rlg/ and they'll turn up here
>>
>>52004485
??

Where is mediaPlayer defined? post code.
>>
File: 100px-Greek_lc_lamda_thin.svg.png (3 KB, 100x167) Image search: [Google]
100px-Greek_lc_lamda_thin.svg.png
3 KB, 100x167
guys, i'm learning functional programming and it's fucking with my head big time.

give me some exercises to solve in a functional style, but go easy on me, i spent 30 minutes yesterday figuring out how to get the length of a list
>>
>>52002455
TERRORIST
>>
>>52004460
Fibonacci recursively is a stupid way to calculate Fibonacci numbers.
>>
>>52004535
Read SICP
>>
>>52004534
MainWindow
 
public partial class MainWindow
{

private DispatcherTimer timer;
public string currentTrack;
public MediaPlayer mediaPlayer = new MediaPlayer();

public MainWindow()


My user control.
    public partial class AudioControls : UserControl
{
public AudioControls()
{
InitializeComponent();
}

private void btnPlayTrack_Click(object sender, RoutedEventArgs e)
{

}


I just need to access the thing, but for some reason my mind has entirely blanked.
>>
>>52004457
nah it's recursive senpai

you don't need to return if you're calling a new function
>>
>>52004562
but dad... i dont wanna use scheme
>>
>>52004314
Then you have 2(n-1) combinations, where n is the length of the series.

Construct an array of zeroes of length n-1; interpet 0 to mean addition, 1 to mean multiplication. Iterate for 2(n-1), treating the array as a binary number just counting up from 0 to 2(n-1) in binary; at each iteration apply the array to your series. This will give you every combination of addition and multiplication of the series.
>>
>>52004344
I meant which one.
And how do I test it? Wine?
>>
>>52004570
Access the thing?
>>
>>52004551
>the naive recursive computation of the Fibonacci numbers is the only way
>>
>>52004535
Solve an arbitrary Kakuro puzzle. We did this in my Prolog/Lisp class
https://en.wikipedia.org/wiki/Kakuro
>>
>>52004570
Where is the user control instantiated?

Not sure how you want to structure this, but you could pass the mediaPlayer instance to AudioControls when you create it, with something like:

    public partial class AudioControls : UserControl
{
MediaPlayer mediaPlayer;
public AudioControls(_mediaPlayer : MediaPlayer)
{
InitializeComponent();
mediaPlayer = _mediaPlayer;
}

private void btnPlayTrack_Click(object sender, RoutedEventArgs e)
{
mediaPlayer.play();
}
>>
>>52004586
You have 2^(n-1)
>>
>>52004596
Google cross platform compilation c++
>>
>>52004650
It's always naive as a closed form exists.
>>
>>52004674
Yeah, I was just about to edit that.
>>
>>52004692
If you have to compute a Fibonacci series, not just one number, an O(n) recursive (or equivalent iterative) solution will be faster. Addition is way fucking cheaper than all the shit going on in the closed form solution, not to mention the closed form has irrational components.
>>
>>52004692
ok let me try again
def fib(n)
uselessvalue = (1 + Math.sqrt(5)) / 2
return ( Math.pow(uselessvalue, n) - Math.pow(-uselessvalue, -n) ) / Math.sqrt(5)
end


am I a programming literate yet?
>>
>>52004788
yes. But you will never be *the* programming literate.
>>
>>52004664
usercontrol is instantiated in the xaml, so at runtime.

I'm not sure why I can't access the properties of MainWindow from my UserControl, that seems like a bit of an oversight.
>>
what is the naming convention for C?

When default compiling with gcc, the output file is called a.out. Is the normal convention to use the -o option to make the compiled file the same name as the input, but with the .out extension?

e.g. - input file is helloworld.c, should the output file be named helloworld.out?
>>
>>52004874
you'll figure it out once you graduate from fizzbuzz
>>
>>52004893
haha epic I can program in different languages you tool
>>
>>52003896
I never use bitfields because compilers often generate complete garbage code from them.
Better to mask and shift yourself, or use intrinsics/asm like x86 bt and bts instructions.
>>
>>52004535
implement red-black trees
>>
How do I add a unix executable to an Xcode project and then use it. I just want to make a wrapper for ffmpeg
>>
>>52004874
Usually it's unit.c -> unit.o -> application
>>
>>52004874
Unix likes typically don't use any file extension for executable files, just name it 'helloworld'
>>
>>52004943
thanks.
>>
>tfw have great idea for website/app but don't feel like dealing with web design bullshit and hosting a server for it to run on
why cant i just like program
>>
Hey /g/, despite the hate with the language, can you recommend good sources to learning Python?
>>
>>52004957
just learn faggot

or tell me what it is and i'll make it.
>>
>>52004843
I feel your pain, bro, I've been in this position In the end it's just best to put the buttons and shit on the same panel as the player so everything is dumped in a single class. You can also fuck around with GetParent, but I think that's just bad practice.

I've had the same in the past with drag and drop functionality to drag objects in one panel to a different panel.
>>
>>52004981
>just learn faggot
i already have and i hate it
its ugly and tedious
>or tell me what it is and i'll make it.
no
>>
>>52004994
tell me
>>
>>52004957
C# .NET web applications, build them from within Visual Studio and you can deploy with a couple clicks from within your IDE to a new server hosted in Windows Azure. Throw in some bootstrap and half your website design is done. It's the easiest way I found to build good quality web application quickly.
>>
>>52004983
The fuck is the point of a usercontrol then? And why the fuck is it called a usercontrol when you can't control anything?
>>
>>52005002
a site like 4chan and reddit but with 50% more memes
>>
>>52004843
>that seems like a bit of an oversight.
It's not. It's good software architecture. A user control shouldn't have any dependencies on you main window.

There's lots of ways you can make you user control access the media player. The best one may be to subscribe to the click events in your usercontrol from MainWindow. Like:

myUserControl.playButton.click += ButtonClickHandler(() => {
mediaPlayer.play();
};
>>
>>52005017
thats actually a pretty good idea
thanks anon
>>
>>52005019
A user control is meant to be very reusable and encapsulated. It's not meant to have any dependencies on the window it's being added to.
>>
>>52005019
A usercontrol is a self-contained thing, it was never designed to control things it's nested within. In your MainWindow XAML you can add an AudioControls object and give it a binding to a method in your MainWindow code. It's not UserControls fault, you're just trying to use it in a way it was never intended.
>>
>>52005022
>4chan and reddit but with 50% more memes
/g/ can you write a program in c that calculates the total amount of memes on the new website (integer data type) from two ints equal to the amounts of memes on 4chan and reddit respectively?
>>
>>52005049
I share your hatred to dealing with downloading packages and installing shit on bullshit Linux. I'm a developer, not a sysadmin.
>>
>>52005037
If I knew where to put that. it'd be great (fucking novice spoonfeeding etc etc)

>>52005070
>>52005072
I'm a novice, I take everything at face value, I assumed that by slapping the usercontrol on the mainwindow XAML it would be completely instantiated at runtime.

But that's having no fucking clue what you're doing for you.
>>
>>52005037

+1 for this. The UserControl should not be looking at things 'above' it in the design (like the MainWindow, or the Panel, etc).
>>
File: 1442779697653.jpg (91 KB, 803x790) Image search: [Google]
1442779697653.jpg
91 KB, 803x790
Anyone have advice on learning C as their first language? Any resources? Everything that I'm finding says I should either already know a language, or should have a basic understanding of common computer programming terminologies.
>>
>>52005075
def meme(4chan, reddit)
return (4chan + reddit) * 3 /4
end
>>
>>52005128
My advice is not to learn C as your first language
>>
>>52005128

The ...for Dummies series is really good for people that don't have any sort of foundation.
>>
>>52005093
well, if I were you honestly I'd just copy all the XAML from the user control and put it in the main window, and just access everything there.
>>
>>52005169
I already despise XAML, it's a clusterfuck mess that I have absolutely no idea how to use effectively.

I was kinda banking on usercontrols being allowed to send an event to "MainWindow" at the very least.
>>
>>52005160
what should he learn then? Python?
hahahahahaa
hahahahahaha
HA!
>>
>>52005160
Thanks for responding, would you care to elaborate as to why you feel this way

>>52005165
Thanks for the recommendation. I'll check them out when I get some cash (broke now from xmas shopping). Any free, online recommendations? Also, how much should I know about hardware before embarking on this journey?
>>
>>52005085
>millennial devs
>>
>>52005207
UserControls are still XAML tho.
>>
>>52005208
>he
>>
>>52005230
True, but I can keep it all contained, and just display it on the page.

It seems a shame that you can't really do this any other way.
>>
>>52005208
def removeShitposts(posts):
return filter(lambda x: not (('Python' in x) and ('ha' in x)), posts)
>>
>>52005213
The C Programming Language (2nd Edition)
>>
>>52005253

Here's a suggestion: ditch WPF.
>>
>>52005230
>>52005253
I'd even settle for an XAML document with designer view that would allow me to do all this stuff in a seperate designer/xaml file so I can keep the utter clusterfuck of XAML from getting too extreme.
>>
>>52005213
seriously tho
Programming in C (4th Edition) by Stephen Kochan is really good.
It doesn't assume you know anything, but doesn't baby you like other books.
>>
while let Some(c) = self.data.get(self.pos) {
if pred(c) {
self.pos += 1;
} else {
break;
}
}

loop {
match self.data.get(self.pos) {
Some(c) if pred(c) => self.pos += 1,
_ => break
}
}

while self.pos < self.data.len() && pred(&self.data[self.pos]) {
self.pos += 1;
}


Which one?
>>
>>52005213
Because C is something to be frustrated with. You can't build something cool in a nice amount of time. It's more trouble than it's worth most of the time. (hurr durr you're just bad). Java or C# are so much more beginner-friendly, because you can fuck around more in those languages and it's a clearer. But if you want to go with C, good luck getting frustrated, people here will gladly tell how to average ints, reverse strings and fizzbuzz. I do like C, but it's not something to start with.
>>
>>52005213
Ignore anyone that tells you not to start with C. You'll pick up something more modern inevitably, but C will teach you a lot of structure and syntax used elsewhere and if you can learn and understand memory management and pointers you are already better than 90% of code monkeys out there.
>>
>>52005316
The third, most likely. Is that Rust?
>>
>>52005316
Top if anyone else is ever going to work with your code.
>>
>>52005339
Yes.
>>
>>52005363
After thinking more, all of them probably have the same performance. Second is definitely the most idiomatically functional.
>>
Don't really get this question: 1) Modify the rain program in Listing 10.7 so that it does the calculations using pointers instead of subscripts. (You still have to declare and initialize the array.)

  1 /* rain_pointers.c -- finds yearly totals, yearly average, and monthly
2 average for several years of rainfall data */
4
5 #include <stdio.h>
6
7 #define MONTHS 12 // number of months in a year
8 #define YEARS 5 // number of years of data
9
10 int main(void)
11 {
12 // initializing rainfall data for 2010 - 2014
13 const float rain[YEARS][MONTHS] =
14 {
15 {4.3,4.3,4.3,3.0,2.0,1.2,0.2,0.2,0.4,2.4,3.5,6.6},
16 {8.5,8.2,1.2,1.6,2.4,0.0,5.2,0.9,0.3,0.9,1.4,7.3},
17 {9.1,8.5,6.7,4.3,2.1,0.8,0.2,0.2,1.1,2.3,6.1,8.4},
18 {7.2,9.9,8.4,3.3,1.2,0.8,0.4,0.0,0.6,1.7,4.3,6.2},
19 {7.6,5.6,3.8,2.8,3.8,0.2,0.0,0.0,0.0,1.3,2.6,5.2}
20 };
21 int year, month;
22 float subtot, total;
23
24 printf(" YEAR RAINFALL (inches)\n");
25 for (year = 0, total = 0; year < YEARS; year++)
26 { // for each year, sum rainfall for each month
27 for (month = 0, subtot = 0; month < MONTHS; month++)
28 subtot += rain[year][month];
29 printf("%5d %15.1f\n", 2010 + year, subtot);
30 total += subtot; // total for all years
31 }
32 printf("\nThe yearly average is %.1f inches.\n\n", total/YEARS);
33 printf("MONTHLY AVERAGES:\n\n");
34 printf(" Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec\n");
35
36 for (month = 0; month < MONTHS; month++)
37 { // for each month, sum rainfall over years
38 for (year = 0, subtot = 0; year < YEARS; year++)
39 subtot += rain[year][month];
40 printf("%4.1f ", subtot/YEARS);
41 }
42 printf("\n");
43
44 return 0;
>>
Is there a way to get a better MediaPlayer than the default one available in C#/WPF?

Almost no exposed properties, so it's utterly fucking painful to use.
>>
>>52005275
Thanks for the recommendation. Unfortunately I read in the preface

>The book is not an introductory programming manual; it assumes some familiarity with basic programming concepts like variables, assignment statements, loops, and functions.

Do you think a quick google search of these terms to get some surface knowledge will suffice for this text? I probably have an above average exposure to math if that would help at all
>>
New to Java, why doesn't this work? The syntax checks out:

public class Arrays {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] a;
a = new int[2];
a[0] = 500;
a[1] = 200;

System.out.println(a[5] + a[2]);
}
}
>>
>>52005450
Ignore this I just spotted the error
>>
>>52005393
Array indexing is equivalent to pointer arithmetic and dereferencing, because the name of an array is also a pointer to its beginning.
a[i] = *(a + i)
>>
>>52005450
a[5] and a[2] do not exist
>>
>>52005393
array[i] is just syntactic sugar for *(array + i), the former being called subscript notation, figure the rest out yourself
>>
>>52005393
make a function for each instead of having everything in main
>>
>>52005439
I don't think you should have any trouble picking that stuff up as you go along.
>>
>>52005315
I'll check it out, thank you!

>>52005334
This makes sense and I appreciate your advice. Unfortunately my knowledge of computers/tech in general leaves much to be desired, so I was hoping I could kill two bird with one stone (by learning about hardware and software) from picking up this language.

>>52005338
Thanks for the advice and motivation!
>>
File: playv2.png (5 KB, 550x147) Image search: [Google]
playv2.png
5 KB, 550x147
>>52005433
>Almost no exposed properties, so it's utterly fucking painful to use.

No, because things like NAudio leak memory.

t. Media Player in C#
>>
>>52005433
C#/WPF isn't doing anything unusual here. This is basic software architecture.

Here's soemthing you can do:
    public partial class AudioControls : UserControl
{
MediaPlayer MediaPlayer {get; set;}
public AudioControls(_mediaPlayer : MediaPlayer)
{
InitializeComponent();
}

private void btnPlayTrack_Click(object sender, RoutedEventArgs e)
{
this.MediaPlayer.play();
}

and then in your MainWindow:
muhUserControl.MediaPlayer = mediaPlayer;

This is not considered good practice though, but will get it working for you.
>>
>>52005493
Can't check if it's playing, where it's playing, set it to play from a certain point, or anything that could be considered useful.

It's just so basic, I'm surprised a package hasn't appeared with a better version MediaPlayer.
>>
Rate my arbitrary int averaging function:
int average(int n, ...)
{
va_list args;
int avg = 0;
int odd[2] = {0, 0};

va_start(args, n);

for (int i = 0; i < n; ++i) {
int val = va_arg(args, int);
avg += val / n;
if (val % 2 != 0)
++odd[val < 0];
}

va_end(args);
return avg + (odd[0] / 2) - (odd[1] / 2);
}

I haven't exhaustively tested it yet though, so I need some situations where it gives the wrong answer.
>>
>>52005522
>Can't check if it's playing

.MediaEnded

>where it's playing, set it to play from a certain point, or anything that could be considered useful.

.Clock
>>
>>52005522
Have you thought about FFmpeg
>>
>>52005538
0/10

def average(*args): return sum(args)/len(args)
>>
>>52005558
So instead of having a competent lib that has all nice useful properties that I can access, I should just fudge a really basic workaround?

>>52005580
I did initially, but I'm a flat out newbie, If I can't install it with nuget then I've got no chance.
>>
>>52002351
a python programmer writing shitty code
>>
>>52005538
>I haven't exhaustively tested it yet

https://github.com/mcandre/qc
>>
File: 10.gif (2 MB, 352x199) Image search: [Google]
10.gif
2 MB, 352x199
>>52005538
>>
>>52005632
that was an unnecessarily hurtful thing to say
>>
>>52005620
>So instead of having a competent lib that has all nice useful properties that I can access, I should just fudge a really basic workaround?

There's no workaround necessary here. You only get clock functionality in clock mode, and whether or not you use that is up to you.

Personally, I do not use it. I don't care about skipping around through songs and the MediaEnded event is more than capable enough to move to another position in the library.
>>
>>52005558
>>52005620
>>52005659

I couldn't even do that, I'd need to access the properties of the MP3 file, which is only doable with TagLib, which doesn't exist any more as far as I can tell.

It seems that this isn't doable for a novice, I assumed that it'd be relatively simple and give me a chance to get used to binding data to the UI, maybe do some Async tasks and stuff.

What other simple project could you recommend? I need something to sink my teeth into that C#/WPF can facilitate at least moderately well without having to rely on trying to find libs that don't exist any more.
>>
>>52004486
What about (a / 3) + (b / 3) + (c / 3)?
>>
>>52005713
>I couldn't even do that, I'd need to access the properties of the MP3 file

You'd need to access it for what purpose? Instead of source, you need to give MediaPlayer a clock (which has a MediaTimeline from a media source). Then you can do what you're trying to do.

Read the MSDN, diggity dawg.
>>
>>52005742
oh god
>>
I'm this anon
>>52005489

Could I get your advice on this? When I run in to terms I'm not familiar with in these tutorials (compiler, for example), should I just do a quick Google to see what they are? Or are there certain ones I should skip?

I don't want to waste too much time with terms I'll pick up along the way, but also don't want top skip anything that is essential
>>
Also, again, ditch WPF. It's for fags.

WinForms for life.
>>
>>52005766
Also, how much time should I spend learning about them?
>>
File: ew.png (272 KB, 470x624) Image search: [Google]
ew.png
272 KB, 470x624
>>52005761
What's the problem senpai?
>>
>>52005775
But I like the whole WYSIWYG UI editor thing, as well as the Mahapps.metro package.

If there was another way to create attractve UI's with a designer view and fuckloads of things to play around with, then I might be interested. But as it stands VS and WPF does it for me.
>>
#include <stdio.h>

long double
average(int *nums, size_t nnums) {
long double avg = 0.0;
for (size_t i = 0; i < nnums; ++i)
avg += nums[i]/(double)nnums;
return avg;
}

int
main(void) {
int nums[] = {1, 2, 3};
printf("%Lf\n", average(nums, 3));
return 0;
}
>>
>>52002204
Matrix reference
>>
write a C function that sums two integers
>>
>>52005854
Converting to floating point numbers is for fags.
>>
>>52005775
>using a deprecated GUI library
>>
>>52005878
int sum(int a, int b) { return a + b; }
>>
>>52005894
>WinForms
>deprecated
>>
>>52005902
doesnt work for a = INT_MAX and b = 1
>>
>>52005467
so what about multi-dimension arrays?
a[i][j] = *(a + i + j) ?
>>
>>52005881
How exactly do you average 1 and 2 without floating point numbers?
>>
>>52005916
Truncate the result, obviously.
>>
int sum(int a, int b){
if (a < b){
return a + (b - a) / 2;
}
else{
return b + (a - b) / 2;
}
}



find a flaw
>>
>>52005911
*(a + (i * a[i].length) + j)
>>
>>52005905
Yes, now that WinRT is getting more used, WPF is also getting deprecated, the thing that made WinForms deprecated in the first place
I bet you still can't let go of COBOL either.
>>
>>52005953
doesnt work for a = anything b = anything
>>
>>52005975
>WinRT
doesn't work for desktop apps though.
>>
>>52005911
Not quite.

This >>52005973 or this work:
a[i][j] = *(*(a + i) + j)
>>
>>52005953
you aren't even trying at this point
>>
>>52005989
It does now, Windows 10 UAP. It didn't work in the past, but now with 1 OS for all devices shit, it does.
>>
>>52005910
Not supposed to work.
>>
>>52005992
>>52005973

This is it?

  1 /* rain_pointers.c -- finds yearly totals, yearly average, and monthly
2 average for several years of rainfall data
3 Uses pointers instead of subscripts */
4
5 #include <stdio.h>
6
7 #define MONTHS 12 // number of months in a year
8 #define YEARS 5 // number of years of data
9
10 int main(void)
11 {
12 // initializing rainfall data for 2010 - 2014
13 const float rain[YEARS][MONTHS] =
14 {
15 {4.3,4.3,4.3,3.0,2.0,1.2,0.2,0.2,0.4,2.4,3.5,6.6},
16 {8.5,8.2,1.2,1.6,2.4,0.0,5.2,0.9,0.3,0.9,1.4,7.3},
17 {9.1,8.5,6.7,4.3,2.1,0.8,0.2,0.2,1.1,2.3,6.1,8.4},
18 {7.2,9.9,8.4,3.3,1.2,0.8,0.4,0.0,0.6,1.7,4.3,6.2},
19 {7.6,5.6,3.8,2.8,3.8,0.2,0.0,0.0,0.0,1.3,2.6,5.2}
20 };
21 int year, month;
22 float subtot, total;
23 float * rain1;
24
25 // a[i][j] = *(*(a + i) + j)
26
27 printf(" YEAR RAINFALL (inches)\n");
28 for (year = 0, total = 0; year < YEARS; year++)
29 { // for each year, sum rainfall for each month
30 for (month = 0, subtot = 0; month < MONTHS; month++)
31 subtot += *(*(rain + year) + month);
32 printf("%5d %15.1f\n", 2010 + year, subtot);
33 total += subtot; // total for all years
34 }
35 printf("\nThe yearly average is %.1f inches.\n\n", total/YEARS);
36 printf("MONTHLY AVERAGES:\n\n");
37 printf(" Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec\n");
38
39 for (month = 0; month < MONTHS; month++)
40 { // for each month, sum rainfall over years
41 for (year = 0, subtot = 0; year < YEARS; year++)
42 subtot += *(*(rain + year) + month);
43 printf("%4.1f ", subtot/YEARS);
44 }
45 printf("\n");
46
47 return 0;
48 }
>>
>>52005911
Oh, and >>52005973 will only work if you also declare the array as 1D with the total size (length * width). If you want to declare it as a multidimensional array but use pointer arithmetic, you can use >>52005992.
>>
>>52005742
int a = 1
int b = 1
int c = 1

Your average function
(1/3) + (1/3) + (1/3) = 0 + 0 + 0
= 0
>>
>>52005910
Undefined behaviour =/= doesn't work
>>
>>52005927
That's not really the average, then.
>>
>>52005988
a = 0, b = 0
>>
>>52006044
>>52006064
The exercise is to average 3 ints
MAX_INT is a valid int
This is not undefined

average(MAX_INT, MAX_INT, MAX_INT) == MAX_INT
>>
>>52006016
you can't access win32 shit from it. It's pretty shitty.
>>
>>52005910
What about:

INT_MAX - ((INT_MAX - a) - b)

Is that ok senpai?
>>
>>52006070
It's integers, m8.
'/' doesn't really divide numbers either.
>>
>>52006070
Why not?
>>
write a C program that calculates pi
>>
>>52006053
Yeah, I used it, and it works >>52006051
. Thanks anon. Although I delayed learning C for like a month (nov to dec) during the middle of the chapter, so I was rather fuzzy when it comes to pointers, and especially pointers + arrays.
>>
>>52006086
If you're writing applications on such high level abstraction, I don't think you're supposed to fuck around with win32 shit
>>
>>52006082
>The exercise is to average 3 ints
No, it was to sum two integers.
If the result is also supposed to be an integer then INT_MIN <= (a+b) <= INT_MAX is a required constraint on the inputs.
>>
>>52006059
Well, that's silly, what doesn't it convert it into float?
>>
>>52006125
int pi(){
return 3.14;
}
>>
>>52006157
Because integer truncation is the behaviour you're looking for most of the time. It would only covert to float if you explicitly tell it to.
>>
>>52006174
doesnt work for pi = INT_MAX
>>
>>52006059
No rounding mode or error tolerance was specified.
>>
>>52006135
>If you're writing applications on such high level abstraction
Sometimes you'll want to do something interesting that requires such access. When you do you don't want it to by absolutely physically impossible because you're running in a sandbox. You might as well make apps in HTML5 if you're using WinRT. At least that works on every platform and version of windows.
>>
File: 1450770707376.png (289 KB, 514x424) Image search: [Google]
1450770707376.png
289 KB, 514x424
>>52006174
>int
>3.14
>>
>>52006192
>in C
>>
>>52006174
I see no calculation happening there.

>>52006125
int pi() {
return 1 * Math.PI;
}
>>
>>52006218
"in C" is not a rounding mode.
>>
Cfags will defend this.

http://code.kx.com/wsvn/code/kx/kdb%2B/c/c/odbc.c
>>
>>52006220
#import <PerfectMathLibrary>

int pi() {
return PERFECTLY_ACCURATE_PI_UP_TO_ALL_DIGITS_OF_PI;
}
>>
>>52006197
All this fighting over Winforms/WPF/WinRT is nice and all, but is there any equivalent that has a nice designer, loads of stuff to play with and comes even close to the simplicity involved in creating a UI in VS?

Starting to get sick of it, but as far as I can tell there is no equal.
>>
Guys, I have a quick question.
As far as I know, all Type in the code below is allocated on the heap.
vector<Type> v;

If that's true, what's a point of a vector like the one below?
vector<unique_ptr<Type>> v;
>>
File: 1421009955630.png (11 KB, 211x246) Image search: [Google]
1421009955630.png
11 KB, 211x246
>>52006247
>>
haha some epic memes you guys got here

god i love generals
>>
>>52006273
vector<Type> v;

This is on the stack
>>
>>52006247
That's probably machine generated code.
>>
>>52006261
But anon, if you're designing a GUI in VS right now, you're probably working with WPF or WinRT (unless you chose for using deprecated WinForms).
>>
>>52002069
>no option for vi, literally the most widespread text editor in the world
>>
>>52006125
#include <math.h>
#include <stdio.h>

int main (void) {
double pi;
fprintf (stdout, "Calculating pi...");
fflush (stdout);
pi = acos (-1);
fprintf (stdout, " Done.\r\n");
fflush (stdout);
fprintf (stdout, "pi == %f\r\n", pi);
return 0;
}
>>
>>52006296
It's not. They even document their obscure shit:
http://code.kx.com/wsvn/code/kx/kdb%2B/c/c/readme.txt
>>
>>52006261
>No.

except....

no...

I dare not speak it...
Thread replies: 255
Thread images: 21

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.