[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: 18
File: DPT.png (389 KB, 934x1000) Image search: [Google]
DPT.png
389 KB, 934x1000
Old thread: >>55360972

What are you working on /g/?
>>
first for C++
>>
>>55367288
second for C++++
>>
Trying to get into programming strictly as a hobby. What's a good language if you don't plan on doing collaborative work? I heard Java, for example, requires a lot of code compared to python.

Also what's a good website for inspiration for software to develop?
>>
>>55367335
Learn C. Every programmer should know C, regardless of anything.
>>
>>55367340
nice meme
>>
>>55367335
This -> >>55367340
After grasping the core concepts you might wanna move to a higher level language or just use libraries.
>>
If I'm piping data into a C program, is there a measurable advantage to encoding it in binary instead of plaintext? Is that faster?
Does it even matter if I'm only sending 5-6 integer messages?
>>
File: 1452403462016.png (79 KB, 307x400) Image search: [Google]
1452403462016.png
79 KB, 307x400
>>55367353
>He doesn't know C
>>
>>55367340
why?
>>
Continued from last thread.. Capitalization cleaned up let's make this more "Enterprise".

int PennieConversion(float decimal_money)
{
int n;
long b;
decimal_money *= 100;
b = round(decimal_money);
n = b;
return n;
}

int HowManyInNum(int num, int num_to_count) {
int count = 0;
if (num < num_to_count) {
return 0;
}

while (num >= num_to_count) {
num -= num_to_count;
++count;
}

return count;
}

int Blub(int& total, int worth) {
int amount = HowManyInNum(total, worth);
total -= (amount * worth);
return amount;
}
int main(void)
{
int total = 1214;
int amount_paid = 0;
int quarters = 0;
int dimes = 0;
int nickels = 0;
int pennies = 0;
int difference = 0;

amount_paid = PennieConversion(9.75f);
difference = total - amount_paid;

quarters = Blub(difference, 25);
dimes = Blub(difference, 10);
nickels = Blub(difference, 5);
pennies = Blub(difference, 1);

cout << quarters << " " << dimes << " " << nickels << " " << pennies;
cin.get();
return 0;
}


I'm thinking this might call for some factory objects, a monetary interface, and some complex architecture to support multiple currencies.
>>
>>55366764
I get distracted if I don't have music going. Too many thoughts going on I have to block some out.
>>
>>55367335
Lisp/Scheme

The language is basically geared towards creating your own little autistic playground where you have infinite power but nobody else knows what exactly you're trying to do.
>>
>>55367335

>>55367340
>>55367369

What these anons said.

But anyway, what do you plan on doing with it? Anything in mind? (e.g. web programming, games, emulators, etc. )
>>
>>55367373
I don't think it will matter, I forgot the reasons to encode to binary though, one of them was to make inviable to let the user modify the text.
>>
>>55367380
you learn how to properly program

you learn how a language influences a computer

just do it
>>
Is there an easy way to make gpxe shutdown when it fails to boot? I can wake my device with WoL, but if it doesn't boot correctly I have to walk over and manually power it down.
>>
>>55367373
Binary encoding is faster, but it would only be noticeable for much larger sets of data.
>>
>>55367385
there needs to be a newline between return type and function name
>>
>>55367425
Can C read binary from stdin, or is the process different?
>>
>>55367373
>>55367425
by "larger sets of data" literally only hundreds of thousands of lines it will make a difference
>>
>>55367410
C is one of the worst languages for a beginner. It has fucked up semantics and irregular syntax.
If you want to learn how to "influence a computer" just learn assembly.
>>
>>55367335
>What's a good language if you don't plan on doing collaborative work
functional languages

Try Haskell
https://github.com/bitemyapp/learnhaskell
start with
http://www.seas.upenn.edu/%7Ecis194/spring13/lectures.html
>>
>>55367432

What shop did you work at that ever did that in c / c++ code? I should probably be thankful I haven't seen that yet.
>>
>>55367446
>Can C read binary from stdin
Yes. It's like any other file.

>>55367451
You're retarded.
>>
I just decided to learn my first language like an hour ago too and started with python. Did I fuck up? Should I start over with C?
>>
>>55367448
So I shouldn't even bother if I'm just sending a 6 byte, MIDI-like message?
>>
>>55367446
Well ascii is 8 bits so input an 8 bit string at a time and cast it to a char

it's really not a realistic option
>>
>>55367464
it makes grepping for function definitions easier
>>
If you don't know C, you basically aren't even human.

t. Cmen
>>
>>55367469
Stick with Python. Once you mastered it, move to C++ if you want to go lower.
>>
If you mix races, you basically aren't even human.
>>
C is good for learning how computers work.
But something like Scheme is better for learning how computer science works.

When you read SICP, it's not full of "well you could do it this way, or you could do it with *this* function, but don't use *that* function; it's considered depreciated" footnotes like C texts are.

It really depends on where your interests lie. If you want to treat your computer like a racecar where you tweak X to make Y happen, learn C. If you want to treat it like a magic tome where you just say X and Y happens, learn Scheme. They're both useful.
>>
>>55367534
>but don't use *that* function; it's considered depreciated
List of deprecated C functions:
gets

Even then, it was actually removed, so you don't even have to worry about it anymore.
>>
>>55367534
scheme got deprecated by Haskell honestly
>>
>>55367469

Just stick with it. After you're comfortable with python move onto to something lower (C, C++, Rust).

C is a language every programmer should eventually learn to at least read.

If you want a job.. It's still mainly SQL, C#, Java, and C++. That is if you actually count SQL as a programming language.
>>
>>55367564
>not homoiconic
>>
>>55367564
haskell is pretty navel-gazing and bean-counting itself, and it's easy for newer programmers to write themselves into a corner
it's not nearly as conducive to learning as a Lisp, which is much looser and freer
>>
File: 1443932041015.jpg (154 KB, 633x558) Image search: [Google]
1443932041015.jpg
154 KB, 633x558
>>55367494
You're right, nigger lover.
>>
>>55367606

Haskell in general is built for and by academics. In general the language always chooses academically interesting approaches rather than increasing programmer productivity.

I'm pretty sure about the only place it has seen successful commercial use is at a few financial institutions.
>>
>>55367410
why is it better than other languages? what defines proper programming?
>>
>>55367391
Probably websites that offer some built in service. Want to build a website that helps video content creators match up(ie: video editor with guy go gathers footage of some extreme sport or whatever). Have a couple of these ideas but no clue on how to go about it. I took intro to java in college last semester. don't see many people using this language for these kinds of projects though.
>>
https://www.youtube.com/watch?v=8G9QIIvSpzE
>>
>>55367735
They're just recommending C because that's what they've been exposed first. They see anyone who doesn't go through that particular rite of passage as a lesser programmer no matter what. There is no rationality behind it.
>>
>>55367800
yea i figured. doubt these advocates even know how to program properly themselves.
>>
>>55367717
>I'm pretty sure about the only place it has seen successful commercial use is at a few financial institutions.
and even then most of them just use Ocaml.

Lisp and Haskell are both largely functional but they're night and day really. Haskell has none of the joyous spirit of exploration that Lisp provides.
>>
>>55367714

I made that picture you fuccboi. :)
>>
>>55367797

What you can do with a degree

Apply for jobs,
Do interviews,
Get rejected continuously because no one wants a fresh college student anymore.
Give in and finally start working retail / flipping burgers and continually try to get a job that isn't fucking you in terms of money.
>>
>>55367832

The places that would want a college student can just get the work done cheaper overseas.
>>
does Ocaml have HKT and typeclasses yet
>>
>C++ has no standard to_string function for objects
why
>>
>>55367875
>HKT
meme
>typeclasses
meme
>>
>>55367908
What would you need it for
>>
>>55367832
You just skipped the steps of spending several years in unpaid internships, working on open source projects, and getting scammed on Upwork in order to build your reputation.
>>
>>55367955

Not so much a meme as a sign of the transition from unsafe code with side effects to mostly safe code with well regulated zones of side effects. This is transition is probably a result of the growing demand for asynchronous multi-threaded applications.
>>
>>55367971
Oh I don't know, for printing objects?
>inb4 stream operators
Whoever thought that was a good way to do it was fucking retarded.
>>
Figuring out how I'd like to design and create a VM. I'm thinking of segmenting everything like the instructions, data and stack, but I'm not quite sure on the logistics on that.
>>
>>55367996

this is a transition that is probably a result of the growing demand for asynchronous multi-threaded applications*

I really need some caffeine right now.
>>
>>55367908

Because there is no "object" type that all objects inherit from.

How should the C++ language know what your object should look like as a string anyways if you don't define the method yourself?
>>
>>55367996
just use functors
>>
>>55368029
No you don't understand.
I can't define the member and have printing functions use it because print functions don't know about it.
Sure I can call it manually, but I don't want to.
>>
>>55367908
They use overloading their memestreams for that.
It's horrible, I know.
>>
>>55368089
Yeah I'm aware of that but I do not want to use it.
It's a terrible fucking hack. Fuck stream operators all together, format strings are superior.
>>
>>55368061

namespace std {
string to_string(const your_obj& o)
{
// Fill in code here, you lazy twat.
}
}
>>
>>55368061
you can override cast operator for const char* m8
>>
>>55367800
>>55367819
No. I was exposed to C only after shit scripting languages and C++ and I still recommend it first. It's a beautiful language.
>>
Why is operator overloading acceptable?

Why should + mean "add two numbers" as well as "append two lists"

How is this not considered harmful as FUCK?
>>
>>55368061

Templates + Design patterns.. If you really need a bunch of objects that can be used by a print function then you should probably be programming to a interface of some sort. I'm pretty sure that's what most languages with a to_string built in are doing.
>>
>>55368126

Because freedom. + Is just a function.
>>
>>55368116
nice coming of age narrative you have there
>>
>>55368126
append two lists is actually ++ in good languages

operator overload is a thing so you can use + for both int and float (and other shit like vectors)
>>
>>55368137
> freedom
Whenever you hear this word, you know it's going to be followed by a justification for something unjustifiable.
>>
>>55368126
because it's controlled by the programmer to be safe. How would it be harmful?
>>
>>55368155

No need. Freedom is its own justification.
>>
>>55368143
Why are you bitter about C? Because you're too stupid to learn it properly?
>>
>>55368156
>>55368150
>>55368137
> cin >> and cout << are acceptable
>>
>>55368150
>you can use + for both int and float
Probably the only case where it makes some sense
And even then it's not too much trouble to have separate syntax for int and float like Ocaml does

I was writing an iOS app the other week and ran into some ridiculous compiler errors caused entirely by operators being overloaded up the wazoo.

I know, I know
>Swift

but there's a deeper, theoretical flaw going on here

One function should do one thing.
>>
>>55368155
Come to Russia, buddy. We all hate freedom, you'll feel at home. I assure you.
>>
>>55368198
it also makes sense for vectors and matrices and everything else where you want addition
>>
>>55368195

Yes. Get rekt, Anon. C++ is not for mere mortals such as yourself.
>>
>>55368228
I'm sorry, but I have some semblance of taste.
>>
>>55368199
luckily my own country is slowly becoming more nationalist and less liberal, but maybe not quickly enough

I'm not trying to be edgy but 'freedom' can seriously go to hell. It's always wielded as an excuse to defend a sub-optimal state of affairs. The average person has nothing to show for 'freedom'
>>
>>55368195
Indeed. There is no safer way to objectify console in and console out.
>>
Is there a quick way to overload functions where the only thing that changes is the parameter.
Dealing with opening files and I need to open a char* or a tchar*. You cant convert a tchar to a char to my knowledge easily.
>>
>>55368198
It makes sense for lots of things. any string library, any big number library. IO. matrix libraries.

and most people assumes that operator overloading is just math operators. you have [] -> in C++, or casting operators . or assignment. these have lots of usability

If you are using operator overloading when it makes no sense, it is no different than bad function names. it is programmer's responsible to make use of it.
>>
>>55368241
Do you hold your pinky up when programming faggot?
>>
File: 5c5.jpg (31 KB, 465x455) Image search: [Google]
5c5.jpg
31 KB, 465x455
>>55368241
>semblance
>taste
>>
>>55368198
generic programming is a good thing, addition function is just adding 2 types together
it is the same with other functions which were made to be generic
>>
>>55367388
you know every language started out as their creator's little autistic playground right?


except they didn't want you to make your own, so they told you the right way to program.
>>
>>55368241
>>55368259
REKT
>>
>>55368259
>>55368276
What?
You don't?
>>
>>55367560
strcpy
strcat
strdup
strtok
bcopy
bzero
...
>>
>>55368243

Just like terrorism is always a excuse to infringe on privacy, due process, and the things that differentiate a citizen from a convict in prison.

>>55368256
Very true. It's a sad fact of life though that a lot of "programmers" abuse it for stupid nonsensical shit.
>>
>>55368298
>strcpy
>strcat
>strdup
>strtok
None of those are deprecated.
>bcopy
>bzero
Those aren't even standard.
>>
>>55368165

God bless America.
>>
>there are people that does
a.add(b.multiply(c.add(e), f.subtract(g)))
because they can't afford operator overloading
this is a sad world
>>
>>55368353
yea, java and Go kek
>>
>>55368353

(add a (multiply b ( (add c e) (subtract f g))))


This makes no sense are you multiplying b by the sum of c and e and then multiplying the result by the difference of f and g or what?
>>
>>55368397
>his language does not have a comma operator
>>
>>55368427

The comma operator functions differently depending on what b is in this case. It could be a class that performs a multiplication between c.add(e) and f.subtract(g) or it could be doing a multiplication using all three.. It's far too ambiguous in this example.
>>
what's the best book for learning Haskell?
>>
>>55368601
I like Learn You a Haskell, but people criticize it a lot since it doesn't show you how to solve real problems. There's Real World Haskell but I didn't read that one fully.
>>
>>55368310

> none of those are depreciated

Why? str{cpy,cat,dup} all share the same problem as gets, no way to specify a limit.

strtok was replaced by strsep.

bcopy and bzero were defined by POSIX, marked legacy in 2001. I didn't know you were such a pedant we were only talking about the standard lib.
>>
>>55368641
>no way to specify a limit
Yes they do. It's called a null terminator.
>>
>>55368353

> operator overloading

The best way to troll people reading your code.
>>
>>55368664
His post too early:

>>55368641
>strtok was replaced by strsep.
strsep is non-standard. Not even POSIX standard.
>marked legacy
legacy isn't quite the same as deprecated.
But even then, they were removed.
>>
>>55368641
gets input from stdin. there is no way to control what user inputs. you can ensure those to be safe
>>
>>55368688
>His
hit*
>>
>>55368601
http://haskellbook.com/
>>
>>55368397
(add a (multiply b (add c e) (subtract f g)))
>>
>>55367288
>/dpt/ - Daily Programming Thread
more like the Daily Phaggot Thread amirite
>>
>>55368427
comma is used for unquoting
>>
>>55368664

And gets is limited by a newline.

I think it was obvious I was referring to srncpy and friends, which let you specify a maximum number of bytes.
>>
>>55368800
It's false to assume that strncpy is a 'safe' strcpy. They have different semantics.

Also, you can guarantee the length of many strings and buffers, so the 'n' versions wouldn't be necessary in those situations and only hurts performance.
>>
>>55367288
i'm bootstrapping a simple lisp in 68k assembly
>>
>>55368800
>And gets is limited by a newline.
a new line that is inputted by user. you can't force user to size of your buffer.
>>
>>55368688

> they were removed

In 2008. Lots of documentation and example code still uses them, and lots of systems still define them, which confirms the original point that C has lots of cruft from the way things were done before.
>>
Why are Indians the best programmers?
>>
>>55368869
They aren't, they just actually put time into what they do and finish what they are working on, unlike you anon. Take a look at their code, its shit, but it at least works.
>>
I would like to bring to attention, as often as possible, that Yuki's face looks awful in the OP image
>>
>>55368903
Projecting this hard

Implying you even finished a program
>>
>>55368255
What the fuck is a tchar?
>>
Does anyone remember that site where you would upload music to a room of users, and the room would stream to everyone at once, and the host would switch in a round robin? Mumuplayer was a clone of it but what was before that?
>>
Night lads
>>
>>55369099
plug.dj?
>>
>>55369105
Fuck off nigger.
>>
A family friendly version of 4chan aimed at kids.
>>
>>55369116
Plug.dj is a terrible clone of what I'm talking about as well. You can't upload tracks in plug, you have to link from youtube or soundcloud. And it's bloated.
All I remember about it was that it had a vinyl record icon or logo or something
>>
I heard Chez Scheme was just open sourced by Cisco. Sounds like a good opportunity to explore the language once more.

Standard Scheme seems to have become an actual thing, with libraries, module system and everything. Sounds pretty exciting, fixes my number 1 complaint about Scheme: fragmentation.

What do you think is the best Scheme implementation? I hear Chez is one of the best ones on the performance side, and it seems to be an actual R6RS implementation
>>
What is the best site for programming practice problems and practice projects?
>>
>>55369141
What software?
>>
So as I said earlier I've started learning my python as my first programming language. I am following this http://automatetheboringstuff.com/chapter2/
And I made this
#Example something like a login
name = ''
password = ''
while 'oer' != name :
print('Username:')
name = input()
print('Password:')
password = input()
if 'oer' == name :
print('Hello Okay')
else:
print('Unknown User')
while 'oer' == name and 'ok' != password :
print('Wrong Password')
print('Password:')
password = input()
if password == 'ok' and name == 'oer':
print('Access Granted')
import time
time.sleep(3)

Is there any way to make this more efficent? Anything wrong with it?
>>
>>55369156
https://youtu.be/8G9QIIvSpzE
>>
>>55369156
I liked CodeEval.
>>
>>55369176
tinyboard+vichan.
>>
>>55368255
some winapi bs
>>
>>55369150
My favorite is Chicken, but I am interested in Chez. I installed it the other day on my Macbook but I still need to get it on my FreeBSD machine, where I do most of my actual work.
>>
>>55369194
hoooly fuck this guy is so salty that he wasted his life and has no employable skills
>>
>>55369274
The only actual benchmark I found of Chez only tested the Petite version, which doesn't actually have the actual optimizing compiler. I mean what is the point

The whole open sourcing thing seems to have happened pretty recently, it was a pain to build it on Windows
>>
>>55369195
moree like this
>>
>>55369308
hackerrank
those are the only 2 that matter
>>
why does [10..1] not work in haskell?
>>
>>55369498
Think it has to do with how the list notation is defined. It's syntactic sugar for a bunch of >>= operations.
>>
the first element in computer programming should be 1 and not 0 it is just a mistake designers made
>>
A MATLAB script that preserves the color saturation across largely different viewing conditions.
>>
>own 2 java coding books
>own Python the Hard Way
>still too stupid to code

is there any hope?
>>
>>55369186
debloated a bit but doesnt have quite the same functionality, it keeps saying hello okay instead of asking password over and over again like the other one
#Example something like a login 2
name = ''
password = ''
while 'oer' != name or 'ok' != password:
print('Username:')
name = input()
print('Password:')
password = input()
if 'oer' != name :
print('Unknown User')
else:
print ('Hello Okay')
if password !=('ok') :
print('Wrong Password')
else :
print('Access Granted')

import time
time.sleep(3)
>>
>>55369561
Anyone can get programming you just need a good teacher to explain it to you. What are you struggling with specifically?
>>
When I do:

fd = open("myfile", O_RDONLY);


it returns a successful file descriptor.

But when I do:

char buf[256];
fgets(buf, sizeof(buf), stdin);
open(buf, O_RDONLY);


and enter myfile in stdin, I get a -1 error status.
What's the difference between the two pieces of code and how do I make the second part work?
>>
>>55369054
kek

More than most of the shitters in this thread
>>
>>55369742
name 3

pro tip you can't
>>
>>55369766
Connect Four minimax (scalable)
Distance Vector Routing spt
Hexic HD clone for linux and wangblows
>>
can someone tell me why Im failing to read in this binary file properly.
    file.seekg(0, file.end);
size = file.tellg();
char *memblock = new char[size];
file.seekg(0, file.beg);
file.read(memblock, size);
file.close();
result = memblock;
//std::cout << "the entire file content is in memory";
delete[] memblock;
>>
whats this dither pattern called?
Definitely not a bayer matrix.
trying to replicate some of the effects in watchdogs 2
>>
>>55369766
>>55369786
niggas don't forget the "post your github" meme
>>
>>55369797
>using shithub in current year
>>
>>55369797
>>55369818
>2015
>not storing all your personal projects on a usb dick

What are you some kind of pleb?
>>
>>55367908
You're embarrassing yourself
>>
>>55369729
seriously how to I pass a simple string variable as an argument to open();

What small retarded mistake am I making?
Or what big one?
>>
>>55369981
sizeof(buf)
>>
>>55368198
This is why we have interfaces, modules, or typeclasses. Define + for numeric like things and then you solve your problem.
>>
>>55369818
when did I ever suggest using github was good? Are you not familiar with post your github?
Do you have autism?
>>
>>55369786
> gaymes
> real programs

kek
>>
>>55369873
If that were true then I'd be embarrassed right now.
Which I'm not.
>>
>>55369596

i follow tutorials

i learn stuff

i can't think of anything to make

i kind of need a lesson plan like "okay take what you learned in this chapter and make a calculator" basically.
>>
>>55370435
If you understood how silly your question was, you'd be embarrassed. You better switch back to Java m8
>>
>>55370550
I'm aware of std::to_string()
I'm talking about a standard to_string() method in objects.
Yes I know I could define one myself, but the standard printing functions don't use them.

I can't do this:
Foo f;
puts(f); // fuck std::cout
>>
>>55370770

You have a few options.

1. Stop being a whiny bitch, and do it like this:

Foo f;
const char *s = f.to_string(); // Implement this yourself
puts(s);


2. Implement an overload for puts that does this for you

3. This

http://en.cppreference.com/w/cpp/language/cast_operator

But above all, stop complaining that the language doesn't know how to print your custom object. It has no idea how to represent your object as a string, and therefore can't print it. Also, puts is a C function, so logically it can only deal with C's data types. It can't even print an std::string without you first using the c_str() method to get a C string out of it.
>>
>>55370952

multiply(1, 0)
multiply(2, -1)
multiply(1, INT_MIN)

Your recursive function is incomplete.
>>
>>55370963
C++ is shit compared to Ruby prove me wrong
>>
>>55370988
I just realized this and have the fixed version on my home server, but can't open my updated repo because hotels hate ssh.
>>
>>55370988
Here senpai, now can I yank my dick around?

#include <iostream>

using namespace std;

int multiply(int a, int b);

int main()
{
int a = 0;
int b = 0;

cout << "Recursive multiplication program for integers";

cout << endl << "Number a: ";
cin >> a;
cout << "Number b: ";
cin >> b;
cout << endl << "Result: " << multiply(a, b);


return 0;
}

int multiply(int a, int b)
{
if (b == 1)
return a;
if (a == 1)
return b;

if (a < 0)
return a + multiply(a, b - 1);
if (b < 0)
return b + multiply(a - 1, b);

return a + multiply(a, b - 1);
}
>>
>>55371001

C++ and Ruby are relatively incomparable languages. Also, even in Ruby, you still kind of have to define your to_s method if you don't want to have your object look like #<Foo:0x00000001d9c190>
>>
>>55371082

multiply(0,0)
>>
>>55371103
if(a==0||b==0)
return 0;
>>
File: Corneliu-Zelea-Codreanu.jpg (10 KB, 180x268) Image search: [Google]
Corneliu-Zelea-Codreanu.jpg
10 KB, 180x268
>>55367288
Could anybody provide me with a resource for C++ practice problems?
Did C in hs and I'm looking to expand into OOP.

Thinking of attempting to make a Snake game but I think it's still way beyond my reach.
>>
IT WAS FREE PIZZA
>>
>>55371143
More like
a | b ? 0 : return 0;
>>
>>55371171
hackerrank.com
>>
>>55371247
I'm pretty sure that is invalid.
>>
>>55371171

If you know basic logic and looping then a snake game is well within your reach. Just use a library like sdl or sfml. It's only going to take around 400ish lines of code. 1000 lines of code if you go a bit ham on it.
>>
>>55367451
C is a >difficult< language for doing text manipulation and for making large, complex programs.
I think it's perfectly fine for beginners, the only qualm being that they won't be able to make anything more than a shitty console program unless they switch over to python or java.
>>
>>55368641
>Why? str{cpy,cat,dup} all share the same problem as gets, no way to specify a limit.
No they do not and there is nothing wrong with that.
>>
>>55369729
fgets returns the \n with it
read the documentation
>>
File: minkowski.png (59 KB, 1530x440) Image search: [Google]
minkowski.png
59 KB, 1530x440
Making some headway with my Minkowski calculator. I'm still sort of straddling full retard though.
>>
Recommend me a small-medium sized project to write and a language to write it in.
>>
>>55371752
create one level of a shmup (with boss)
x86 asm
>>
File: 1454473002433.jpg (405 KB, 1992x1287) Image search: [Google]
1454473002433.jpg
405 KB, 1992x1287
could anyone lead me to a webpage search implementation that searches a certain string through data stored on txt/csv files on the server ?

rather than tntsearch & larvel, thanks
>>
>>55371752
>small-medium sized
>>
>>55372033
>Small to medium sized
What's the problem?
>>
>>55372055
>>55371973
I misquoted. Memes aside it would be difficult to write a shmup in C let alone x86. Fun, but I can't go killing myself just yet.
>>
>>55371973

SDL + x86-64 ASM sounds like a fun combination.
>>
A 3D cheese pizza MMORPG in WebGL
>>
>>55372357
dumb tripfag
>>
>>55372376
What's the best way to learn webGL?
>>
>doing exercism
>accidentally realize a hashmap is the solution to match a word with its anagram
I am not a smart man.
>>
>>55372951
Which programming language are you using for your exorcisms?
>>
>>55373027
Sepples
>>
>>55368131

That's not really the issue at hand. Scripts run and work the problem is making them run when I press the 'run' button instead of right after you browse for it.

    def InitWindow(self):
self.master.title("GUI")
self.pack(fill=BOTH, expand=True)

# Browse button
buttonBrowse = Button(self.master, text="Browse", command=self.ChooseFile)
buttonBrowse.place(x=350,y=10)

# Run button
buttonRun = Button(self.master, text="Run", command=lambda: self.RunFile())
buttonRun.place(x=410,y=10)

# Quit button
buttonQuit = Button(self, text="Quit", command=self.ClientExit)
buttonQuit.pack(side=LEFT)

# Tool menu
menu = Menu(self.master)
self.master.config(menu=menu)

# Put these in the order that they are supposed to appear!
file = Menu(menu)
file.add_command(label='Open File', command=self.ChooseFile)
file.add_command(label='Exit', command=self.ClientExit)

menu.add_cascade(label='File', menu=file)

def ChooseFile(self):
fname = askopenfilename(initialdir="C:/",
filetypes=(("Batch script", "*.bat"), ("Python script", "*.py"), ("All files", "*.*")),
title="Choose a file")

try:
ePath = Entry(self.master, text=fname)
ePath.place(x=5,y=15)
except:
print("Failed to open a file")

def RunFile(self, fname: StringVar):
fdir = os.path.split(fname)[0]
p=Popen(fname, cwd=fdir, creationflags=CREATE_NEW_CONSOLE)
>>
>>55368700
It makes me sad to see Snoyman and other enterprise quality minions taking over Haskell.
>>
is there a good list of beginner exercises that i can do after i finish learn python the hard way? the book just gives you the code to type in most of the time so i feel like im gonna forget this shit quick if i dont start applying it to something
>>
>>55372498
mozilla webgl tutorial
sorry for late response, i was busy fapping
>>
I know nothing about C, so here goes:

I'm trying to read a .WAV header into an array of unsigned 8-bit integers.

In Scheme it's as simple as
(read-u8vector 44 (wavfile-port))


which gives me
#u8(82 73 70 70 222 153 42 0 87 65 86 69 102 109 116 32 40 0 0 0 254 255 1 0 68 172 0 0 136 88 1 0 2 0 16 0 22 0 16 0 4 0 0 0)


I'm reading about reading binary files in C, and apparently I have to read the bytes into a char array? This is what I have:
FILE *fileptr;
char *buffer;

fileptr = fopen("wavfile.wav", "rb");
buffer = (char *)malloc(45*sizeof(char));
fread(buffer, 1, 44, fileptr);
fclose(fileptr);


The resulting array is
82 73 70 70 -34 -103 42 0 87 65 86 69 102 109 116 32 40 0 0 0 -2 -1 1 0 68 -84 0 0 -120 88 1 0 2 0 16 0 22 0 16 0 4 0 0 0 -1


You can see that some of the indices are similar to the Scheme vector. Those are where characters appear in the .WAV header. The numerical values are fucked though.

tl;dr - how do I get the binary data I've read to appear as unsigned integers like in the Scheme example
>>
>>55373348
replace
char *buffer;

with
unsigned char *buffer;
>>
>>55373358
oh ok, that makes sense.

I was trying to replace it with
unsigned int *buffer;
and getting all kinds of weird numbers. Didn't think about that though. It works, thanks.
>>
>>55373435

An int is (usually) four bytes, where a char is one, so that would have interpreted four of your numbers as one
>>
>>55373118
I'm a mongo, can someone help me with this?
>>
>>55373435
weird, but still, keep the signed and unsigned keywords in C in mind from now on. you're welcome senpai
>>
>>55373463
>python
there's your problem
>>
>>55372025
>inject all text files into Elasticsearch with like ten lines of code
>wrote a basic elasticsearch query
>>
reminder that you can't spell orgasm without ASM
>>
>>55373590
can't spell
Has Kelly slept with you yet?

Without Haskell
>>
>>55373606
Kelly is either an ugly manfaced tranny or the answer to that is always 'no'
>>
>>55373348
>(char *)
>sizeof(char)
>45
>44
>I don't know what the fuck I'm doing
ishyggy
>>
>>55373713
the tutorial said I need to allocate an extra byte for \0

and I don't know what I'm doing. I'm writing C out of necessity, not because I like it.
>>
>>55373713
Even COBOL is better than C
>>
>>55373904
can't spell COBOL without C
>>
>>55373737
A WAV-header is not a string. It can contain zeroes that do not terminate the string. You won't
printf ( "%s", output );
anyway. Also, A WAV-header is not really 44 bytes long. It can be as long as you want it to be (there are four bytes that contain the length of the header at 0x10).

So what you really need to do is, go into the file, seek for 0x10, read out the length of the header, go back to the start and then read the whole header. Something like
size_t read_wav_header( uint8_t **output, const char *filename )
{
FILE *file_ptr;
file_ptr = fopen( filename, "rb" );
uint32_t length_of_header;
fseek( file_ptr, 0x10, SEEK_SET );
fread( &length_of_header, 1, 4, file_ptr );
length_of_header += 20;
*output = malloc( length_of_header );
if ( *output )
{
fseek( file_ptr, 0x00, SEEK_SET );
fread( *output, 1, length_of_header, file_ptr );
return length_of_header;
}
else
return 0;
}

That function returns 0 if it failed to read the file and the length of the header if it succeeded. Use it like
int main ()
{
uint8_t *output = NULL;
size_t L = read_wav_header( &output, "test.wav" );
for ( int i = 0; i < L; ++i )
printf( "%02x ", output[i] );
}

for example.
>>
what if i want to declare a global variable from a function in c? e.g. i call a function with a value, then i want a global array to have the size of that value
>>
>>55373986
>i want a global array to have the size of that value
Global variables must have a constant size.
>>
>>55373944
Thanks for the very thorough explanation.
For the time being I'm just working on some basic playback of a few samples for use in my own compositions, rather than a program released for general usage, so I can guarantee the header size is going to be what I want it to be. The reason why I'm reading the header in the first place is just to make a couple of ioctl calls for the sampling rate, channels, etc later

if the code ever becomes something larger than that, I'll implement you advice
>>
>>55374081
and of course I can guarantee the channels and sampling rate too

the only think I really care about is the number of frames. I figured it'd be quicker to read the value from the header than the manually count everything in the file
>>
>>55373986
int *global_array;

void alloc_array(int size) {
global_array = malloc(sizeof(int)*size);
}


Something like that.
>>
I moved my lazy fat ass and configured the volume buttons cause it was very lame of me to have to open alsamixer in terminal everytime I wanted to change the volume.

>volume.sh
#!/bin/sh

[[ -z "$1" ]] && exit

if [ `echo "$1" | rev | cut -c 1` = "-" ] && [ `amixer -c 0 get Master | egrep -o "[0-9]+%" | tr -d "%"` = "0" ]
then
amixer set Front mute
beep
elif [ `echo "$1" | rev | cut -c 1` = "+" ] && [ `amixer -c 0 get Master | egrep -o "[0-9]+%" | tr -d "%"` = "100" ]
then
beep
elif [ "$1" = "0" ]
then
amixer set Front toggle
notify-send "amixer" "`amixer -c 0 get Front | sed s/\\ \\ // | grep \\^Front`"
else
[[ `amixer -c 0 get Master | egrep -o "[0-9]+%" | tr -d "%"` = "0" ]] && amixer set Front unmute
amixer set Master "$1"
notify-send "amixer" "`amixer -c 0 get Master | sed s/\\ \\ // | grep \\^Mono`"
fi


>rc.lua
[...]
-- {{{ Key bindings
globalkeys = awful.util.table.join(
[...]

-- Multimedia keys
awful.key({ }, "XF86AudioRaiseVolume", function () awful.util.spawn_with_shell("~/.config/awesome/volume.sh 1+") end),
awful.key({ }, "XF86AudioLowerVolume", function () awful.util.spawn_with_shell("~/.config/awesome/volume.sh 1-") end),
awful.key({ }, "XF86AudioMute", function () awful.util.spawn_with_shell("~/.config/awesome/volume.sh 0") end),
awful.key({ "Shift" }, "XF86AudioRaiseVolume", function () awful.util.spawn_with_shell("~/.config/awesome/volume.sh 5+") end),
awful.key({ "Shift" }, "XF86AudioLowerVolume", function () awful.util.spawn_with_shell("~/.config/awesome/volume.sh 5-") end)
)
[...]
>>
>>55374331
what if i want to do this, but with a struct instead of int? I can't access the data through ->
>>
>>55374333
>rc.lua
So much repetition, Jesus
>>
are expr1 and expr2 equivalent?

expr1 = (not a or not b)

expr2 = not (a or b)

>>
>>55374358
I'm pretty sure the same thing but with the struct name would work.
>>
>>55374406
No. Look up De Morgan's laws.
>>
>>55374406
No.

not (a or b) == not a and not b

There's some law about that. I don't remember the name.
>>
File: Screenshot - 020716 - 14:25:44.png (23 KB, 690x310) Image search: [Google]
Screenshot - 020716 - 14:25:44.png
23 KB, 690x310
>>55374412
>>
>>55374444
Try for all cases: a=0,b=0; a=1,b=0; a=0,b=1; a=1,b=1
Also nice quads
>>
>>55374444
I don't know what the operator precedence for whatever language that is, but the first expression might be getting parsed as
(not (a or (not b)))
>>
>>55374478
its python
>>
>>55374478
Actually, that particular parse wouldn't produce the right answer.
Anyway, I don't know anything about whatever language that is, so I can't give you a correct answer.
It's possible that 0 == true in that language or something, and only values like nil/null and false are 'false'.
>>
>>55374444
It happens to be true for some cases, but not for all.
>>
>>55367288
>>55367308
out of all the dialects of C++
what is the most usable right now ? I am just starting to learn it, and I want ot be employable with it.

c++14 ? or c++11 ?
>>
>>55374561
C++17
>>
>>55374561
C++98
>>
>>55374561
C99
>>
File: 1467278660571.gif (650 KB, 647x363) Image search: [Google]
1467278660571.gif
650 KB, 647x363
So I'm trying to learn programming, and I really want to, but this god damn C book is so frustrating
I got 'Head First C' since it was recommended as a beginner book but the first thing it tells me is that it assumes I already know Java (I've only ever done simple stuff in Python before), I decide to try and go on with it but it just keeps on assuming I know so many things that I actually don't and doesn't explain any commands to me.

Should I just continue with C or just go learn Java, I'm genuinely upset at this right
>>
>>55374561
C90
>>
File: 9780131103627.jpg (63 KB, 491x648) Image search: [Google]
9780131103627.jpg
63 KB, 491x648
>>55374595
Try this book.
>>
>>55374605
That doesn't even exist, stupid nigger faggot.
>>
>>55374595
Read a different book then.

>>55374617
That's not a beginner book either.

>>55374623
Yes it does. That is when ISO released it's C standard, which is exactly the same as the ANSI C89 standard, with some formatting differences.
>>
File: 1372772523983.jpg (31 KB, 352x450) Image search: [Google]
1372772523983.jpg
31 KB, 352x450
>>55374639
>it's
>>
>>55374561
PB98
>>
>>55374595
Learn Python first. Then read >>55374617
>>
>>55374667
Yes I noticed I did that too after I posted, but I considered it too small of an error to correct.
Good job anon, you totally called me out. That entirely invalidates what I said, doesn't it?
>>
>>55374683
>Learn Python first
Jesus, what fucking terrible advice.
>>
>>55374683
NEVER learn Python
>>
>>55374595
Try this book.
>>
>>55374704
>>55374709
>learn some easier thing before you jump head first into programming is a terrible advice
>>
>>55374683
Python is not to be learned EVER, if you every do make sure you are already employed, or succeeded at at least 250 personal projects in any other language there is (even HTML is better and faster than python)
>>
>>55374751
>learn something that will destroy your thought process FOREVER just because retards think it's easier

For people that aren't retarded, it isn't easier
>>
>>55374751
Learning something that will cause bad habits and overall structure failure in the long term is bad. If you want something easy to learn, go ahead learn C++ basics
Thread replies: 255
Thread images: 18

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.