[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: K&R hime linked list copy.jpg (551 KB, 1280x1440) Image search: [Google]
K&R hime linked list copy.jpg
551 KB, 1280x1440
old thread: >>55338200

What are you working on, /g/?
>>
File: 1462849576018.jpg (700 KB, 1053x1070) Image search: [Google]
1462849576018.jpg
700 KB, 1053x1070
>>55346344
Is that what is commonly known as a "Dicky Ricky"?
>>
first for GO

* no gc
* no forced indentation
* approved by UNIX gods (PIKE, THOMPSON)
>>
>>55346319
It looks unstable as fuck if it wasn't maintained properly, but if it get's the job done on a relatively low budget, why the hell not.

On first impressions and tries this evening, it looks as if you could get shit done with it. I can understand why someone would use it in the first place.
>>
File: C vs C++.png (463 KB, 785x678) Image search: [Google]
C vs C++.png
463 KB, 785x678
I wanted to write a quick cgi file in C and I ended up writing a whole framework for collecting GET and POST field/value pairs in a neat searchable list.

It's longer than the actual cgi script.
>>
>>55346425
what? it has GC and worse yet it has forced code style
>>
>>55346457
I swear this guy on the right is my old geography teacher.
>>
>>55346425
Go has all the cons of C with none of the benefits.

>pointers
>NO POINTER ARITHMETIC ALLOWED!
>>
>>55346425
Ancient feeling piece of shit language. Let the idiots who ruined UNIX and C create another language and wonder where you fucked up. Brilliant Google.
Try something modern like Swift or sjw best pick that is Rust.

To back my shit up: http://yager.io/programming/go.html
>>
>>55346518
Rust is pretty good
>>
is it me or is C really shit at regex
>>
>>55346559
Why use regex when you can roll your own string manipulation.
It's what C is best at.
>>
>>55346344
>More forced memes
XDDD
>>
>>55346559
>>55346593
>using regex
>>
>>55346528
Indeed it is. Wrote a 5000 line program in it and trust me, that will never crash! However sjw are taking over this promising project...
>>
Is there any way to determine which host did a client use to connect to a TCP server or is the resolv purely client sided and such information is not disclosed to the server?
>>
>>55346634

Worst they can do is control some terminology. Surely, they will not create intentional security holes in the runtime and tell us it's oppressive to fix it...
>>
>>55346875
If the code was written by a woman it's literally rape to delete their contributions.
>>
>>55346613
You have got to be retarded
>>
>>55346559
regex in C is not usually used for internal string processing, it's just for user interface. If they want to search with regexp or whatever.
>>
>>55346613
Regular expressions are the most efficient way for checking whether some string is in a regular language.
Learn your CS theory, you scrub.

On a related note: backreferences are shit.
>>
>>55346952
>>55347018
>being too autistic to pick up on blatant shitposting
>>
>>55346634
>Wrote a 5000 line program in it and trust me, that will never crash!

What does this program do?
>>
>>55346634

5,000 lines isn't really that large of a program. The better question is what level of complexity is in said program.

I mean managing a bunch of unsafe code blocks at the bare metal level is completely different from your standard desktop app.
>>
>>55347234

That's sizable for a personal project.
>>
>>55346559
C is just shit.
>>
File: 7phuJaq6.jpg (42 KB, 512x512) Image search: [Google]
7phuJaq6.jpg
42 KB, 512x512
>>55347282

Exactly. It's time to embrace the fyoocher.
>>
where do I get started if I want to program
>>
>>55347322
Opening your text editor.
>>
>>55347240

Fair enough. Though if it's something of low complexity you're talking about only a week or two project maybe less. Speaking from personal experience I had a few 2,000 - 3,000 line projects that only took a weekend.
>>
>>55347333
>Though if it's something of low complexity you're talking about only a week or two project maybe less. Speaking from personal experience I had a few 2,000 - 3,000 line projects that only took a weekend.

Fair enough, I've had a few 1.5k line projects that were weekend projects. All I meant was that 5k lines is nothing to scoff at.
>>
>>55346344
C# or Python? I had a class on C# on the basics but I hate it would Python be better to get into programming?
>>
>>55347436
Definitely Python. Use C# only if you want to be Microsoft's bitch.
>>
>>55347462

C# is free as in freedom, though.
>>
>>55346593
I'm trying to fuck with a GET string that can have really inconsistent lengths.

Yes, I'm using C for CGI scripting but I have literally no other ideas for learning C.
>>
>>55346559
C is really shit, no abstractions allowed

Like I'm a kid
>>
>>55347322
>Attempt to code something you like.
>Fail.
Repeat the above steps until you succeed.
>>
>>55347436

Python is good if you just want to get projects done and you're not worried about getting extreme performance.

You might also look into Go / Ruby / Rust . Be flexible ideally a programmer should be picking up a new language every year or two.
>>
>>55347504
You could do something like this.
    if (!getenv("CONTENT_LENGTH")) /* someone accessed the .cgi directly */
return 1;

unsigned POST_len = atoi(getenv("CONTENT_LENGTH")); /* get POST query */
char *POST_query = (char *) malloc(sizeof(char) * POST_len + 1);
fread(POST_query, POST_len, 1, stdin);
POST_query[POST_len] = '\0';
>>
>>55347322
Hormones immediately and Amazon ship you some knee high socks.
>>
>>55347548
>spoof content length
>memory exhausted

lol
>>
>>55347548
>>55347558
Why is C such a piece of shit?
>>
>>55346518
This guy likes to shill for Rust, but rust doesn't even have HKT or how verbose it is
>>
File: 1403101451615.png (1006 KB, 940x719) Image search: [Google]
1403101451615.png
1006 KB, 940x719
>tell interviewer I feel most comfortable in C#, php, SQL

okay what should I study on these to make sure I don't fail the interview? inheritance? function calls?
>>
>>55347566
he's bluffing
>>
>>55347583
I would look for another job
>>
>>55347583
Boxing / unboxing, interfaces, abstract classes, lambda expressions, delegates, some design patterns, anonymous types, LINQ.
>>
>>55347583
>>55347608
RT #rekt
>>
>>55347586
I'm not, just curl with custom header that sets content-length header to ulong max and spam the endpoint.
>>
>>55347623
    if (POST_len > 10000) 
return 1;
>>
File: 1404399358132.png (170 KB, 490x355) Image search: [Google]
1404399358132.png
170 KB, 490x355
>>55347614

>delegates
> interfaces
>abstract classes

>tfw I suck at these
>>
>>55347653

Nice fix.
>>
>>55347653
see that wasnt that hard, now was it?
>>
>>55347572

Let's face it you just want to use Haskell / Scala.
>>
>>55347683
You just need to know what they are, anon and some use cases for them. I doubt they will ask you to implement a design pattern using those.
>>
>>55347683
Not hum but they're simple, you just need to practice.
Delegates are collections of "function pointers".
Interfaces are "contracts" that the class should implement if inherits from this interface.
Abstract classes are just classes to provide a base which can't be instantiated.
>>
>>55347722
>>55347725

I only ever got around to using them once. my work and classes never really used them or needed them.

this is for a QA analyst position. I seemingly did well in the first interview.
>>
Is there a way to isolate a specific digit in a float for evaluation/comparison?

For instance, could I isolate the number in the hundredths place of a float so that I could see if it were greater or less than 5 and round the entire float accordingly?
>>
File: gg.png (12 KB, 500x363) Image search: [Google]
gg.png
12 KB, 500x363
>in a C++ class and the homework is this
I guess you have to start somewhere.
>>
>>55348003
>system("pause")
install engtoo
>>
>>55348003
I learned nothing but bad habits from being taught C++ as a first language.

Also the instructor encouraged a really shit mindset.
>USE VECTORS FOR EVERYTHING
>NEVER EVER IMPLEMENT DATA STRUCTURES YOURSELF
>SMARTER PEOPLE THAN YOU HAVE WRITTEN BULLETPROOF LIBRARIES FOR EVERYTHING YOU NEED!!!
>>
>>55348000
I think num%1 would leave you with just the decimals if you want to compare.
>>
>>55346344
EXPLAIN THIS PROTIP YOU CANT
>>
>>55348000

>could I isolate the number in the hundredths place of a float so that I could see if it were greater or less than 5 and round the entire float accordingly?

if you want to find the sub digits do this:

take the float you want to check and multiply by what place you want to see and then use modular division example:

x = 1.45;
z = (x * 100) %100 //gets the hundredth place
z = (x*10) % 10 //gets the tens place
>>
>>55348003
>system("pause");

REEEEEEEEEEEEEEEEEEEE
>>
>>55348061
you should look up how floats work
>>
Guys, I just want to make games. Is Python good enough?
>>
>>55348041
So, it was you're instructors fault, not C++.
>>
>>55348091
emone
>>
>>55348023
>>55348075
In a program like that, is there a better way to keep the console from closing?
>>
>>55348091
Pick up Lua, it's simplier than Python, it's beautiful, and Love2D is a great game framework with a fuck ton of third party libraries that will ease everything.
>>
>>55348112
>keep the console from closing
why?
>>
>>55348070
Holy shit anon, that's a pretty ingenious solution, will try it out.
>>
>>55348112

I always just waited for the user to enter a key. so in the case of C++ just use cin; that way you just wait for any key hit.
>>
>>55348129
OK. Should I learn Python at one point?
>>
>>55348091

Depends on the type of game you'd like to make. Try looking into pygame to start out. Eventually you're going to have to make / use modules in a faster language to get adequate performance (C, C++, Rust, etc).
>>
>>55348112
Console.ReadKey

Or whatever it is in that library.
>>
>>55348130
The instructor runs the programs, and he needs to see the displayed message from cout.
>>
>>55348112
Open it in a terminal, or if you're in a shitty operating system, cmd :^)
>>
>>55348153
Probably yes, it's great for automation and quick hackjobs that get the job done.
>>
>>55348155
Right now I want to make something 2D, no 3D.
>>
>>55348164
>instructor can't grade that without running it

I smell pajeet
>>
>>55348164
Can't your instructor just open the terminal first and run your program from there?
>>
>>55348178

Then pygame would be fine. You should learn both Python and Lua if you're actually interested in game dev. They're very commonly used languages for scripting.
>>
Should I learn Python 2 or 3?
>>
>>55348164
Seems like your instructor is not very good with computers.
>>
>>55346344
What's the joke? This is just stupid. Deleting the last node of a linkedlist is easy as fuck, it's literally just traversing and updating the pointer.
>>
>>55348209
stop spreading misinformation
>>55348178
learn c++
>>
>>55348112
getchar();
>>
>>55348264
What's wrong with pygame and Python?
>>
>>55348157
I searched around, and it looks like cin.get() is the best option.
>>
>>55348230

Python 2 support ends in 2020, Python 3 has had a slow adoption rate. Honestly, I'd go with Python 3 .

>>55348264

C++ / C is still mandatory after a point.. I mean it's is the king of game dev languages. Really not good for beginners though.
>>
>>55348112
A universal solution is

#include <iostream>
#include <string>

int main(){
printf("%s", "Press enter to continue...\n");
std::string nothing;
getline(std::cin, nothing);
}


But you shouldn't need it at all
>>
>>55348342
std::cin.get();
>>
Can you with instagram's api (or some other way) request all images a user has been tagged in, similar to what you get when searching "photos of <name>" on facebook?
>>
>>55348361
that works too
>>
File: 1338032124341.jpg (27 KB, 300x300) Image search: [Google]
1338032124341.jpg
27 KB, 300x300
Have you ever tried to code conscious AI, /dpt/?
>>
>>55348381
Strong AI is impossible.
>>
>>55348340
So basically as long as I don't do anything complex like 3D or an RPG like final fantasy, Python/Lua is fine.
>>
>>55346344
Motherfucking JavaFX GUI portfolio thing because I'm an autist and want to implant that shit into my webpage.
>>
>>55348415
Why would it be impossible?
>>
>>55348445
Cause >>55348415 is a fucking faggot. Why else.
>>
I gotta learn C and C++. In what order should I learn these? I've been getting a lot of mixed messages from people I've asked.
>>
>>55348461
Learn C.
Forgo C++.
>>
So wait. Why is starting with Python a bad idea?
>>
>>55348432

Yeah as long as it's nothing too intense you'll be perfectly fine using lua / python. Odds are you'll be doing just small projects for a long period of time (Text adventure games, tic tac toe, pong, etc)

The first small mario / side scroller / old school doom style shooter is always way more complex than people think. As for final fantasy it's a giant undertaking for a single developer.
>>
>>55348507
it isn't don't listen to /dpt/
>>
>>55348075
#include <conio.h>
#include <string.h>

void main()
{
int i;
char* string = (char*) malloc(sizeof(char) * 1024);

printf("Please input a message: ");
gets(string);

for(i = 0; i < strlen(string); i++)
{
if(string[i] == 'e')
{
string[i] = 'x';
}
}

printf("\n%s\n", string);
getch();
return 0;
}
>>
Yo Opengl bros.
Im trying to learn how this thing works and its giving me a headache. Suppose I have to windows opened. How do I tell opengl which window to render to. Right now its just picking the second window that was created.
>>
>>55348461
C then C++11

C++14> is retarded for what it's trying to be
>>
If I ever decide to go the pure CS academic route and get a PhD, I'm going to set a hard rule in my classes that all assignments must terminate unless explicitly stated otherwise. Students who use hacks like system("pause") or cin.getline() to extend the duration of a program beyond what is necessary will receive a 0 on the assignment.
>>
File: 1462970641659.png (754 KB, 736x715) Image search: [Google]
1462970641659.png
754 KB, 736x715
>>55348518
>void main
>conio.h
>Casting malloc
>sizeof(char)
>gets
>getch
>Leaking memory
Everything seems too wrong.
This must be a ruse.
>>
>>55348517
fuck off. It's because it's a language with cancerous syntax and gives you a false sense of security. Learn it only after you know a language which works more like a computer like C. Even then I've lately prefered JS over Python for scripting shit.
>>
>>55348526
Sounds like the only PhD you'll be getting is a PhD in Autism, fampai.
>>
>>55348526
Oh btw, Ruby, how'd your gb roguelike project thing go?
>>
>>55348519
>OpenGL
>2016
>not looping the rendering
Are you even trying?
>>
>>55348562

Well, in working on my master's degree right now. A PhD would not be too much harder if I were to decide to play there.

>>55348570

Just got the sprite sheets I'm going to need from a friend. Going need to try a lot of messing around and see how to handle animations in GB first though...
>>
>>55348526

That's fine, I'll just use sleep(10000).
>>
>>55348627

-50 pts. Try to improve the performance of your program by removing extraneous function calls.
>>
>>55348579
Im trying. I just have no idea what Im doing.
And its looping but only rendering to the second window created.
>>
>>55348635
>Try to improve the performance of your program by removing extraneous function calls.

That's a good idea, I'll put the entirety of the source into main. That way I don't have to call a whole bunch of functions.
>>
>>55348658
Or use an inline function :^)
>>
>>55348646
Did you happen to override the first window with the second one? Just post the code fagit.
>>
>>55347709
He says Rust has a better type inference system, but I still see types being written in rust

can it not automatically infer the type of arguments like most other good languages?
>>
Basically if you're not using Haskell, Idris, Coq, or Agda, then your not programming, you're just working on an assembly line.
>>
>>55348635
What if my code is slow because I'm using Ruby?
>>
>>55348701

He says rust & haskell have a better type inference system than Go.

I'm failing to see what your argument is here.
>>
>>55348726
I gave ur mum the coq last nite
>>
>>55348684
Its a lot of code from a tutorial on how to use opengl. Set up for 1 window. Now Im trying to modify it for 2 windows.
It just seems like the issue is I have no idea how Im supposed to specify which window to render to.
If I knew the function to do so or just how its normally done I could probably implement it, but google examples use glut.
>>
>>55348800
my mum is ur mum, bruv
>>
>>55348807
Do you need to render both windows or do you just want to choose which one to render?
>>
>>55348798
this
https://github.com/uutils/coreutils/blob/master/src/cat/cat.rs#L164-L165
fn write_bytes(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
show_ends: bool, show_nonprint: bool, show_tabs: bool) {

>Because Rust and Haskell are both based on the Hindley-Milner type system
Only haskell does it right, Rust still requires you to write the type. But he listed Rust with haskell in this advantage, even when it isn't true for Rust

We can see here Go and Rust are the same, both still have to write the type of arguments.
You even have to write the return type!
fn fact(x: i32) -> i32 {
if x == 0 {
return 1;
}
x * fact(x - 1)
}

fn main() {
println!("5! is {}", fact(5));
}

where it should do
fn fact(x) {
if x == 0 {
return 1;
}
x * fact(x - 1)
}

fn main() {
println!("5! is {}", fact(5));
}

quite easy to infer it is a int, like how Haskell would've been able
>>
>>55348003
You have no style man

Here you go
#include <stdio.h>
#include <stdlib.h>

typedef struct{
unsigned char detector;
int offset_store;
unsigned char verify;
char *string;
}__MASTER_CHAR_CONVERT;

volatile unsigned short int convert_function(char *(*string_input)){
string_input += '\0';
int i = -1;
__MASTER_CHAR_CONVERT conv = {
.verify = 0,
.detector = 'x',
.offset_store = (int)'x'-(int)'e'
};
while(*(string_input[++i]) != '\0'){
++conv.verify;
}
if(string_input[conv.verify] != '\0') exit(0);
for (int k = 0; k < conv.verify; ++k){
if(*string_input[k] == 'e'){
*string_input[k] = (char)((int)*string_input[k] + conv.offset_store);
}
}
return 1;
}

int main() {
__MASTER_CHAR_CONVERT inst = {.string = ""};
fscanf(stdin, (const char*)inst.string);
if(convert_function(&inst.string) != 1) exit(0);
fprintf(stdout, "%s\nPress any key to continue...", inst.string);
scanf("");
}
>>
Suggest to me a small to medium sized project.
>>
>>55349045
An app that insults its users based on contacts and recent texts
>>
>>55348923

It's actually a conscious choice on the developer's part in rust. They want to avoid the extra confusion and potentially code breaking changes that type of inference would add. The compiler can do it easily they just don't believe the potential downsides are worth implementing it (Mainly type errors non locally).
>>
>>55348432
RPG should be possible, don't aim for 3D until you gain an understanding of C/C++ though.
>>
>>55349014

Nice.
>>
>>55349082
sure but the guy comparing got it wrong, it's just the same as go's type inference
>>
>cs degree meme.jpg
This is from project Euler.
Can someone give me a hint as to a non-retarded way of doing this?
// ----------------------------- Problem 5 -------------------------------
// SMALLEST MULTIPLE: 2520 is the smallest number that can be divided by
// each of the numbers from 1 to 10 without any remainder. What is the
// smallest positive number that is evenly divisible by all of the
// numbers from 1 to 20?
// -----------------------------------------------------------------------
int problemFive()
{
int i = 1;
bool found = false;
while(found == false)
{
if( (i % 2 == 0) && (i % 3 == 0) && (i % 4 == 0) && (i % 5 == 0) && (i % 6 == 0) && (i % 7 == 0) && (i % 8 == 0) && (i % 9 == 0) && (i % 10 == 0) )
{
found = true;
}
else
{
i++;
}

}
return i;
}


It's bad enough with 9 conditionals, but to do 19 is a joke.
>>
>>55348519
You switch the current context.
>>
>>55349014
I don't think my intro class teaches style like that.
>>
>>55349206
That was a joke you should never write it like that
>>
>>55349217
i do what i want
>>
>>55349183
Use a loop then?

static int problem_five()
{
int i = 0, n = 0;

while(true) {
for(n = 2; n <= 20; ++n) {
if((i % n) != 0) {
++i;
continue;
}
}

break;
}

return i;
}
>>
>>55349183
it's called a loop.
>>
>>55349131

Go just figures out the type of the variable on the right hand side of the assignment operator (.

Rust doesn't actually determine the type until it's used. So it can determine types in situations where the type on the right hand side of the operator isn't immediately known.

A good illustration of this I saw on reddit a while back is this code sample.

let mut v = Vec::new();  // What type of vector is this?
v.push(1u8); // It's a u8 vector
>>
>>55349183
#include <iostream>

long gcd(long a, long b)
{
return !b ? a : gcd(b, a%b);
}

long lcm(long a, long b)
{
return a * (b / gcd(a, b));
}

int main(void)
{
long res = 20;
for (long n = res - 1; n > 1; --n) {
res = lcm(res, n);
}
std::cout << res << std::endl;
}
>>
>>55348876
Ideally both but I cant even do 1 at a time.
using
>glfwMakeContextCurrent(m_window);
will only let me set stuff before the first render otherwise it crashes.
>>
>>55349183

You can start with this:

obviously anything even can be divided by two. And anything divisible by 8 can be divided by 4.

Also 3 and 6 are redundant because you are testing with 9
>>
>>55347322
https://www.udacity.com/
Take the CS 101 class and the class after you learn so much important shit and it's free.
>>
>>55349247
>>55349259
Ah, yes, a loop.
IDIOT. I don't why it took me a bit to figure it out.
I ended up doing the same thing basically:
int problemFive()
{
int i = 1;
bool found = false;

while(found == false)
{
i++;
found = true;
for(int j = 2; j <= 20; j++)
{
if (i % j != 0)
found = false;
}
}
return i;
}

Takes forever, though.

>>55349272
This is nice looking, my friend always uses the "?" and ":" and it always throws me. I'm still Fisher Price My First Programmer.

>>55349310
This is good thinking, I like the way you think.
>>
>>55349377
>Takes forever, though.
because you're using a brute-force approach and not using simple math like gcd or lcm
>>
File: nodejs.jpg (14 KB, 280x205) Image search: [Google]
nodejs.jpg
14 KB, 280x205
Working on a node library that adds annotations to express server applications
>>
>>55349416
>Working on a meme meme that memes memes to meme meme memes
>>>/g/wdg
>>
>>55349183
>>55349247
>>55349272
>programming project Euler questions
These are supposed to be done mathematically with pen and paper, or at the very least you program the math like >>55349272 did
>>
>>55348366
>>55348366
>>55348366
>>55348366
>>55348366
>>
>>55349377

The ternary operator is little shorthand for a if else statement.


( comparison operation or boolean value) ? do this if result is true : do this if result is false
>>
>>55349424

None of those are memes?
>>
>>55349183
lad...

#include <iostream>
#include <string>

int main(){
int n = 0, found = 0;
while(!found){
n += 20;
int lol = 1;
for(int i = 1; i <= 20; ++i){
if((n%i) != 0){
lol = 0;
}
if(!lol) break;
if(i == 20 && lol){
found = n;
}
}
}
printf("%d", found);
}
>>
>>55349497
>#include <iostream>
>#include <string>
>>
>>55349377
Think about it from first principles. Decompose the numbers 1 to 20 into their prime factors and the powers of each one of them e.g. 20 -> { 2 -> 2, 5 -> 1 }. Then merge these sets of prime factors, using the greatest power for each repeated prime. Then you have the prime factor decomposition of the answer, from which you can compute the answer.
>>
>>55349424

>>>>/g/wdg

RESTful servers aren't strictly web development. Though they do use http protocol.
>>
>>55349497
>main function doesn't return
>>
>>55349525
In both C++ and C99 onwards, reaching the end of main() without returning anything implicitly returns 0.
>>
>>55349424
t. NEET
>>
>>55349537
We use C90 here, kid.
>>
>>55349507
wrote this over a scratchpad c++ file I already had open and forgot to take out the includes

>>55349525
ever heard of implicit return retard?
>>
>>55349556
No. Now who's the retard?
>>
>>55349550
You're a dumbass.
>>
>>55349537
>>55349556

>assuming every computer runs the newer version of C++

kys
>>
>>55349579
Such witty repartee!
>>
>>55349591
Are you using pre-standardised C++ or something?

>>55349599
What did you expect?
You said something stupid, so I called you a dumbass.
>>
>>55349550
ansi C also implicitly returns 0
>>
>>55349591
every version of c++ has implicit return
>>
>>55349644
No it doesn't.
>>
>>55348537
Not him but void main implicitly returns 0 at the end of main
Casting malloc is required if you want to compile as c++ although idk why he would
sizeof(...) is good practice
gets is terrible, no defending there
getch is fine to hold for input
Memory is freed when the program exits and since it is only mallocd once and is such a short program it is fine.
>>
>>55349574
you, apparently
>>
>>55349680
excuse me? is that a way to treat a lady?
>>
>>55349679
ok kid, he was writing in C which casting malloc is shit. If he was actually writing C++ then writing pure C in C++ is the biggest offense.

sizeof(char) is always 1 (CUE THE DEBATE)

conio is unavailable on linux

you should free the malloc or you'd be leaving hanging pointers i.e. leaking memory
>>
pt. 1
enum Direction {
foreward = 0;
backward = 1;
left = 2;
right = 3;
nuetral = 4;
};

int magnitude(int a, int b){
float mag = sqrt((a * a) + (b * b));
return mag < 0 ? (mag * -1) : mag;
}

int mathDirection(int a, int b){
int dir = arctan(b / a);
if (dir < 0) {dir += 360;};
return dir;
}

enum Direction movementDirection(int dir){
enum Direction Direct;
if (dir > 45 && dir < 135){
Direct = foreward;
return Direct;
} else if (dir > 135 && dir < 225) {
Direct = 2; //left
return Direct;
} else if (dir > 225 && dir < 315){
Direct = 1; //back;
return Direct;
} else if (dir > 315 || dir < 45) {
Direct = 3; //right;
return Direct;
} else {
Direct = 4; //nuetral
return Direct;
}
}

>>
>>55349702

Gender equality.. Male / Female / Trap is of no relevance to that person's statements.
>>
>>55349702
Women are fighting for gender equality, so I've put it upon myself to treat each gender as equally shitty
>>
>>55349720
pt. 2
task usercontrol (){
while(1){
enum Direction direct = movementDirection(mathDirection(vexRT[Ch3], vexRT[Ch4]));

switch(direct){
case foreward:
motor[port1] = magnitude(0, 0);
motor[port2] = magnitude(vexRT[Ch3], vexRT[Ch4]);
motor[port3] = (magnitude(vexRT[Ch3], vexRT[Ch4]) * -1);
break;

case backward:
motor[port1] = magnitude(0, 0);
motor[port2] = (magnitude(vexRT[Ch3], vexRT[Ch4]) * -1);
motor[port3] = magnitude(vexRT[Ch3], vexRT[Ch4]);
break;

case left:
motor[port1] = (magnitude(vexRT[Ch3], vexRT[Ch4]) * -1);
motor[port2] = magnitude(vexRT[Ch3], vexRT[Ch4]);
motor[port3] = (magnitude(vexRT[Ch3], vexRT[Ch4]) * .3);
break;

case right:
motor[port1] = magnitude(vexRT[Ch3], vexRT[Ch4]);
motor[port2] = (magnitude(vexRT[Ch3], vexRT[Ch4]) * .3)
motor[port3] = (magnitude(vexRT[Ch3], vexRT[Ch4]) * -1);
break;

case nuetral:
motor[port1] = magnitude(0, 0);
motor[port2] = magnitude(0, 0);
motor[port3] = magnitude(0, 0);
break;

case default:
motor[port1] = vexRT[Ch1];
motor[port2] = vexRT[Ch1];
motor[port3] = vexRT[Ch1];
break;

}

}

}
>>
>>55349711
sizeof is good practice. it doesn't matter what it returns. obviously a char is 1 byte but that doesn't mean you should break practice just because you know something...
When the program exits its memory is wiped. There is no memory leaked afterwards you dumb fuck.
>>
>>55349679
>Memory is freed when the program exits and since it is only mallocd once and is such a short program it is fine.
That's OS dependent. Most modern operating systems will free the memory used up by the process, but there's no guarantees.
>>
>>55349679
>Not him but void main implicitly returns 0 at the end of main
"void main" is a non-standard entry point.
Only "int main(void)" and "int main(int argc, char *argv[]" (or equivalent) are standard entry points.
>Casting malloc is required if you want to compile as c++ although idk why he would
It's unnecessary repeating of information. Also, trying to write shit which will compile as both C and C++ (especially the modern versions) is completely stupid. They're completely different languages.
>sizeof(...) is good practice
sizeof(char) is guaranteed to be 1 and is completely pointless.
>getch is fine to hold for input
First, it's non-standard shit.
Second, you don't need to fucking hold the program up at the end. Stop using such a shitty environment that doesn't even let you see the output of your program after it's finished executing.
>Memory is freed when the program exits and since it is only mallocd once and is such a short program it is fine.
That's technically not guaranteed, but that's not really the point and isn't an excuse for being sloppy. People are going to think you're fucking shit if you leak memory.
If there isn't a free for every malloc, you have failed as a programmer.
>>
>>55349733
pt. 3
Learning to code here. This is the code I made for a kiwi drive vex robot. Some feedback would be nice as I am looking for was to improve.
>>
>>55349766
why define an enum just to ignore it and use their values instead?
Direct = 1;
Direct = 1;
Direct = 3, etc
>>
>>55348164
either your instructor runs from terminal, or if he's using an IDE he sets a breakpoint at the return, and if he's using VS then he can "start without debugging" which pauses at the end.

there is ZERO reason to use extremely exploitable system calls.
>>
>>55349787
For some reason my ide wouldnt let me use the definitions. it forced me to use the values.
>>
Going on vacation for like a week, I'll have an ipad but no computer otherwise. Looking for a good book on programming to read during that time. Something more theory than practice. I'm sorta interested in design patterns, is the head first book any good? Likewise are there any good interactive programming apps on ios? It doesn't look like it but I would be interested.
>>
>>55349804
>there is ZERO reason to use extremely exploitable system calls.
What does that even mean.
>>
>>55349736
see>>55349757
>>
>>55349897
if someone places an executable called "pause" in the same directory as working directory of the program, it will execute "pause".
>>
>>55348366
>>>/g/wdg/
>>
>>55349183

loops/recursion

Here's my brute force solution:

isqrt :: Integer -> Integer
isqrt = floor . sqrt . fromIntegral

partFactors :: Integer -> [Integer]
partFactors x = [ y | y <- [1..isqrt x], x `mod` y == 0]

factors :: Integer -> [Integer]
factors x = (partFactors x ) ++ reverse [x `div` y | y <- partFactors x]

prime :: Integer -> Bool
prime x = partFactors x == [1]

primeFactors :: Integer -> [Integer]
primeFactors x = tail [ y | y <- factors x, prime y]

pFactorize :: Integer -> [Integer]
pFactorize 0 = []
pFactorize 1 = []
pFactorize x = takeWhile (/=0) ([h] ++ pFactorize y)
where h = head (primeFactors x)
y = x `div` h

pFactorizeList :: [Integer] -> [[Integer]]
pFactorizeList [] = []
pFactorizeList (x:xs) = [pFactorize x] ++ pFactorizeList xs

plistUnion :: (Ord a) => [a] -> [a] -> [a]
plistUnion [] [] = []
plistUnion x [] = x
plistUnion [] y = y
plistUnion (x:xs) (y:ys)
| x == y = [x] ++ plistUnion xs ys
| x < y = [x] ++ plistUnion xs (y:ys)
| x > y = [y] ++ plistUnion (x:xs) ys

listUnionReduce :: (Ord a) => [[a]] -> [a]
listUnionReduce xs = foldl (\acc x -> plistUnion acc x) [] xs

result = product (listUnionReduce (pFactorizeList [1..20]))
>>
>>55349897
any time you're using syscalls in a userspace you're fucking up
>>
>>55349891
>interested in design patterns
Idk, just search for a given pattern and study that.
>Likewise are there any good interactive programming apps on ios?
Coda.
>>
>>55349891
TIS-100P is on iPad
>>
>>55349971
>Executing a program is "executing a syscall".
Please get your fucking terminology right.
A syscall is when you call the kernel, not some random program.
>>
>>55350010
who said that
>>
>>55350048
They were complaining that executing the program 'pause' at the end of your program was an "extremely exploitable system call".
>>
>>55349964
what language is that and what kind of psychopath decided on that syntax?
>>
>>55350094
No, you misunderstood. Look here

http://cboard.cprogramming.com/tech-board/58131-system-function-security-vulnerabilities.html
>>
>>55348041
>IMPLYING YOU SHOULDN'T USE VECTORS FOR EVERYTHING

Was today a hot day in india, pajeesh?
>>
>>55350131
Yes, I know system() is pure garbage, but calling it a syscall is flat-out incorrect.
Sure, system() will inevitably call some syscalls, but it's not one itself.
>>
>>55350112

Haskell, friend. The single best language ever.
>>
>>55349183
you don't need to check 6, 8, 10, 12, 14, 15, or 20
Those are all implied true if 2, 3, 4, 5, 7, and 9 are true.
>>
>>55348537
>not opening any type of handle
>insisting he's somehow leaking memory
literally where, where the fuck
>>
>>55349943
Uh, so what?
If a person or program has the access necessary to place that program there, they have complete access already.
>>
>>55350197
He calls malloc in the second line of main, and it is not freed.
>>
>>55350197
Right where it says "malloc"
>>
>>55350178
and to add, you also dont need to check 18.
>>
>>55350155
Funnily enough he's not totally wrong

mov eax, 029h
syscall


is sys_pause
>>
>>55350245
That is not what
system("pause");
is doing, at least not directly.
>>
So I'm trying to learn make, but there's something bugging me:

AFAIK, make won't build the sources again if it doesn't detect any changes in it, or in its dependencies.
However, on my system, running
make build
too times in a row still re-builds everything, even if I didn't modify the code.

daniel-laptop:dummy daniel$ make build
cc -c math.c
cc -c main.c
cc main.o math.o -o calc
daniel-laptop:dummy daniel$ make build
cc -c math.c
cc -c main.c
cc main.o math.o -o calc


Here's my current directory:
├── Makefile
├── main.c
├── main.h
└── math.c

Here's the Makefile:
CC = cc
DEPS = math.o
EXE = calc

build: math main
$(CC) main.o $(DEPS) -o $(EXE)

main: main.c
$(CC) -c main.c

math: math.c
$(CC) -c math.c

clean:
rm $(EXE) *.o


And here's the code:
// main.h
int add(int, int);
int substract(int, int);

// main.c
#include "main.h"
#include <stdio.h>

int main()
{
printf("Welcome to calc V1.0\n");
printf("1 + 1 = %d\n", add(1, 1));
printf("1 - 1 = %d\n", substract(1, 1));
}

// math.c
int add(int x, int y)
{
return x + y;
}

int substract(int x, int y)
{
return x - y;
}


I'm running GNU Make 3.81 on OSX 10.11
Can someone shine some light on this issue? What am I missing here?
>>
>>55350336
Your main and math targets should be main.o and math.o
>>
Guys I have an internship exam coming up, and the coverage apparently is given functions how do you make a certain program. How the fuck should I practice this shat.
>>
>>55350353
>>55350336
I also forgot to mention that 'build' should be $(EXE).
The targets need to be the name of the file they create.
>>
>>55350374
First work on being able to competently type on a keyboard if you're going to ask for help
>>
>>55350353
>>55350382
>Your main and math targets should be main.o and math.o
>'build' should be $(EXE)
Ok, I'll rename the targets and give it a shot.
>>
>>55350374
Either you can into logic or you cant.
No point in studying for that.
>>
Studying for my programming final on saturday.

I remember posting on a /dpt/ about my midterm and got lots of motivation from you guys :D.

All I need is a 75 on the final and I get an A,
pls no cloning binary search tree with recursion
>>
>>55350426
programming final for what class, just general programming?
>>
Is there a fast way of drawing pixels to the screen. Like say I knew the color of each pixel and wanted to draw the image that way.
In my head the drawpixels command in opengl sounds really slow. I feel like it would just be faster to edit a pictures pixels and then draw the picture to the screen.
>>
>>55350471
What, a texture?
>>
>>55350471
huh

any draw will be slow if you're not using parallel processing and a GPU
>>
>>55350245

If you are referring to the i386 Linux syscall, that is 29 decimal, not 29 hexadecimal. It would be 01Dh. Also, on 32 bit Linux processes, syscalls are made using interrupt 0x80, not the syscall instruction. On 64 bit Linux, the syscall number for pause is 34, or 0x22.

http://docs.cs.up.ac.za/programming/asm/derick_tut/syscalls.html
https://filippo.io/linux-syscall-table/
>>
>>55350426

Well a Chip8 emulator is a relatively simple project. You could also do a basic lisp parser or calculator program.

It really depends on the level of course.
>>
>>55350438
2nd year java, planning on learning C++ after class ends saturday. Is the best way to get good at actually designing a program by choosing random projects to do?

Creating a UML diagram totally boggled my mind, and I have no idea on how to get better.
>>
>>55350570
Yes. Or contributing to projects on github.

UML is not only a meme, it's a pajeet meme fantasy. Don't sweat that bullshieet.
>>
>>55350336
>>55350353
>>55350382
>>55350422

Okay, I finally made it. make now shows
make: `calc' is up to date.


Here's the Makefile now (oversimplified):
calc: main.o math.o
cc main.o math.o -o calc

main.o: main.c
cc -c main.c

math.o: math.c
cc -c math.c


For some reason I thought you could name your targets arbitrarily.
>>
anybody else /drunk/ here?
>>
>>55350570

2nd year java should be enough for the chip8 project. This should be enough to get you started ignore the poor formatting.

http://pastebin.com/BbFvxgiA

It's from a old early first draft of my own version in c++.
>>
Why haven't you guys switched to FiM++ yet?

https://esolangs.org/wiki/FiM%2B%2B
>>
>>55350606
Ballmer peak?
>>
How did you guys get so good at programming?

Is there any good websites which go from beginner to advanced practice problems and projects to help you become very good at programming?
>>
>>55350622
I tried writing a wikipedia article about it and they told me to go fuck myself.
>>
>>55350659
>How did you guys get so good at programming?
By programming shit. You don't get good overnight.
>>
>>55350680
What have you programmed?
>>
>>55350659

Get the basics of a language down.
Choose a project.
Code the project.
Anytime you don't know how to do something look up how to do it and why it is done that way.
Experiment.
Repeatedly and infinitely do stupid shit that you won't know was stupid shit until you review old code in the future.
Read code from others.
Follow all of these steps until you stop programming or die.
>>
>>55350659
by learning in this order

assembly -> C -> C++ -> Java -> Javascript -> Pyshit -> Golang -> Ocaml

next on the list is hasklel but I won't enjoy it
>>
>>55350702
Nothing too huge. Mostly some stuff to do with automation of shit I do, and several university assignments.
>>
>>55348701

The point of not having type inference is because it is very useful for making buggy code compile and run.
>>
>>55350592
Okay so I learned how to use Git for my group project but none of my group members wanted to learn the commands from the terminal.

However, what's a good resource to find projects to contribute to?

And UML diagrams aren't that important? I'm just terrible at class design. For ex, I have no idea how to convert the project "Create a video player" into multiple classes, maintain Model View Controller guidelines, and make it efficient.
>>55350614
Hey, thanks for that. Little lost though on what to do. When I am trying to do this project should I expect to be googling often? I'm worried googling fundamentals will cripple me later on.
>>
>>55350674
There really doesn't need to be a Wikipedia article about a joke language that's invented by autists and is nearly unusable
>>
>>55350755
I've done a chip8. You should have the fundamentals down by now. Have a list of chip8 opcodes and it should be self explanatory from there if you know how opcodes work.
>>
Someone teach me to program I am too lazy to look stuff up
>>
>>55350755

Googling is nothing to be ashamed of as long as you learn the "why and how" of any answers you find. Don't ever copy and paste code. Learn why they did it that way and how it works.

As for uml.. that bullshit is just for brain dead management and academics. It's better just to have a concise design document and a clear idea (Written as part of the documentation) of how the various parts of your program need to interact.

If you don't know enough about the problem to make a design before starting just do the smallest pieces possible to get parts of it functioning and then combine them together. After you've solved it go over the code and figure out how you can do it better next time or how you can refactor it to not be a cluster fuck.

Fucking up is normal and will happen often. Until you gain experience everything will be a mess in your programs. Actually, even after gaining experience it'll still be a mess. There is always room to improve.
>>
>>55350822
(you)
>>
>>55350833
How do you get really good though? I still struggle with programming large applications even after reading different programming books and watching different tutorials and trying different projects
>>
>>55350818
Yeah well all I've learned so far is a bunch of data structures and how to implement and use them.

Chip8 seems really confusing, any intermediate step for me to get up to speed?

>>55350833
Yeah I make sure to understand what I find and code it myself, but I feel like it's cheating in a way because I would have not figured it out.

Check this out,

http://codingbat.com/prob/p105136

I had absolutely no idea how to write the recursive call. Never even heard of using the or comparison. However, once I looked at a sample solution, it all made sense, but I feel like I truly don't know the answer.
>>
>>55350862

Just code shit and learn why people who are better at it than you do the things they do.

There is no easy route. It's literally all repetition and research. As you get better you'll notice things that you should of fixed in your previous work and you'll start noticing things in your current work that are making projects more difficult than they need to be.

>>55350818

This pastebin was a full list of opcodes.. They may not be accurate though I could only find a very very early copy of the emulator.

http://pastebin.com/BbFvxgiA
>>
>>55348257

>the last node

Who says you're trying to delete the last node dumbass?
>>
>>55346344
I think I prefer all the anime over all this GPU craze.
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.