[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 334
Thread images: 30

What are you working on, /g/?

Old thread: >>59121588
>>
>>59131250
Computers are trash.
>>
Why would anybody use a language that doesn't let you choose whether to allocate on the stack or on the heap?
>>
File: 2046170.jpg (1MB, 2755x1575px) Image search: [Google]
2046170.jpg
1MB, 2755x1575px
Why would anybody use a language that isn't C?
>>
File: Akagi.Ritsuko.full.133927.jpg (2MB, 2951x4366px) Image search: [Google]
Akagi.Ritsuko.full.133927.jpg
2MB, 2951x4366px
Why are you still not programming an AI in C for your 2D waifu?
Are you simply not clever enough or something?
>>
I'm reading Learn You a Haskell and it's going pretty good so far.

Any tips?
>>
>>59131416
C++ and Fortran have better performance in some situations.
>>
>>59131426
learn C
>>
>>59131442
I already know C
>>
File: 1486454915151.jpg (79KB, 1280x720px) Image search: [Google]
1486454915151.jpg
79KB, 1280x720px
C is trash
>>
>>59131426
Learn Lisp.
>>
>>59131453
make something then
>>
>>59131426
become a carpenter, you will be happier
>>
>>59131506
jesus
>>
how do I introduce myself into OOP? every time I want to, I get to the point that the book or whatever resource says "interface" or "virtual" and I get discouraged. I consider myself a good programmer overall and I used C with classes (C++) to make stuff.
>>
>>59131416
They have goals and deadlines.
>>
>>59131542
CLOS
>>
File: 1382762764241.png (42KB, 184x237px) Image search: [Google]
1382762764241.png
42KB, 184x237px
>>59131474
>>
>>59131564
>they are the exploitable bitches of capitalism
>>
>>59131542
>I get to the point that the book or whatever resource says "interface" or "virtual" and I get discouraged
That's your body rejecting bullshit. It means you're destined to become a great programmer who has a hard time finding a job
>>
whats the most spaghetti line you've written today?

i'll start:

data = sorted([[x[1],float(x[2])] for x in list(csv.reader(data_file))[1:]], key=lambda x: x[1])
>>
>>59131401
Why would anybody use a language that assumes a stack and a heap?
>>
File: 1470792067398.png (36KB, 268x237px) Image search: [Google]
1470792067398.png
36KB, 268x237px
Employed Haskell programmer here
>>
>>59131725
public bool canMoveOnTerrain(Coordinate newCoord)
{
return invalidTerrain.Contains(currentWorld.checkTerrain(newCoord.xWorld, newCoord.yWorld)) ? false : true;
}

OOP was a mistake
>>
>>59131735
Because that's how the Windows, Mac, Linux, etc. work.

Because that's how most architectures work efficiently.
>>
>>59131760
>? false : true
>>
File: 1319651961963.png (315KB, 1024x490px) Image search: [Google]
1319651961963.png
315KB, 1024x490px
>>
unsigned int jump = 0;

jump = inBuf[inPos];


inBuf is defined as char* inBuf

I've confirmed that inBuf[inPos] = 0xAF (175).

So why the fuck does jump = -81?
>>
>>59131802
>unsigned int
>-81
You're full of shit
>>
>>59131576
Make capitalism gone then.
>>
>>59131757
Employed OCaml
programmer here

Enjoy your lazy language anon.
>>
>>59131757
>>59131833
enjoy doing web shit, codemonkeys
>>
>>59131885
jealousy
>>
Is Scheme fast enough to develop games in?
>>
>>59131817
You head is full of shit, retard.

No matter how I check the value of jump it is always -81 at that point. After checking the value of jump for the entire loop I see that jump is negative 321 out of 1086 times.

itoa (jump,tempStr,10);
strcat(testBuf, tempStr);
strcat(testBuf, "|");
>>
File: dba.png (1MB, 818x943px) Image search: [Google]
dba.png
1MB, 818x943px
>>
>>59131818
Capitalism will outlive humans.
>>
>tfw know Java but too lazy to learn about the little differences of C# and Java to learn C#

What it do?
>>
>>59131936
Yes.
>>
>>59132417
Which Scheme implementation(s)?
>>
>>59132427
C
>>
>>59132380
try to make a program in c# with your java knowledge
>>
>>59132453
I tried
(+ 3 4 5)
in C and got a compiler error. I'm using gcc 6.3, is there a flag I need to enable?
>>
>>59131725
Not really spaghetti, but pretty noisy:
(format t "~3@{~{~a~^ ~}~:*~^~%~}" '(1 2 3))

from previous thread.
>>
How do I escape this infinite loop without losing my variable updates? If I use break everything works fine except my variable updates reset back to 0

def start_game(n):
"""
The core function of the game and it handles the score
"""
print("Starting the game now.")
player = 0
computer = 0
draw = 0
while n is True:
result = play_once(True)
if result == 1:
computer += 1
print("I win!")
print("You won {} times, computer won {} times and {} draws.".format (player, computer, draw))
elif result == 0:
draw += 1
print("Game drawn!")
print("You won {} times, computer won {} times and {} draws.".format (player, computer, draw))
elif result == -1:
player += 1
print("You win!")
print("You won {} times, computer won {} times and {} draws.".format (player, computer, draw))
continue
while n is False:
result = play_once(False)
if result == 1:
computer += 1
print("I win!")
print("You won {} times, computer won {} times and {} draws.".format (player, computer, draw))
elif result == 0:
draw += 1
print("Game drawn!")
print("You won {} times, computer won {} times and {} draws.".format (player, computer, draw))
elif result == -1:
player += 1
print("You win!")
print("You won {} times, computer won {} times and {} draws.".format (player, computer, draw))
continue
response = input("Do you want to play again? ")
if response == 'yes':
result = who_plays()
elif response == 'no':
print("Goodbye!"); quit()
>>
>>59132633
split up your code into smaller pieces, like one function for the initialization, one for the main loop etc.
>>
>>59132633
How do I read your spaghetti without losing my sanity? Break that shit into smaller functions and less fucking while blocks.
>>
>>59132633
Initialize them outside of the function
>>
>>59132633
who thought getting rid of brakes was a good idea?
>>
Can someone give me a quick rundown on gdb remote debugging?
Like what's the difference between gdb or gdbserver? Do I need to cross-compile gdb/gdbserver to communicate with a program on a different platform?
>>
Can anyone recommend me the correct function to use here rather than fscanf

I originally had code that printed each word, rather than line, but I am trying to get the line count whilst retaining the ability to split each word (without using strtok)

I have the code below
    while (getline(fp2, line, MAXLINE) > 0) 
{
line_count++;
while(fscanf(line,"%s", wordcheck)!=EOF)


But I get a compiler warning saying that I cannot take char array to FILE * with fscanf. Anyone else know how I would us a similar function to fscanf to process words in a line?
>>
>>59132690
>>59132692
Just look at this then
while n is True:
result = play_once(True)
if result == 1:
computer += 1
print("I win!")
print("You won {} times, computer won {} times and {} draws.".format (player, computer, draw))
elif result == 0:
draw += 1
print("Game drawn!")
print("You won {} times, computer won {} times and {} draws.".format (player, computer, draw))
elif result == -1:
player += 1
print("You win!")
print("You won {} times, computer won {} times and {} draws.".format (player, computer, draw))
continue

What's happening is when the cursor reaches continue it goes back up to the top of the while statement. I want the cursor to go down the function to
response = input("Do you want to play again? ")
instead of repeating the while loop infinitely
>>
>>59132877
set n = False ?
>>
>>59132877
See >>59132690 and >>59132692
Split your damn code and don't use fucking while loops, where you don't need them!
>>
>>59132876
int
main(int argc, char **argv)
{
char line[4096];
while (fgets(line, sizeof(line), stdin))
if (ismatch(argv[argc - 1], line))
fputs(line, stdout);
return 0;
}
>>
planning to do my version control system to sync config files and others between my computers
the key idea is that files have absolute paths and same file may have different paths for different clients
the server will be my bananapi
never did network programming any recommendations for network protocol and lib for c++ I guess
>>
I have problems coming up with solutions to practice problems in my programming book

What do I do?
>>
Recommended text editors for C?
>>
>>59132972
vim
emacs

Don't use nano or atom or sublime or vs code
>>
>>59131250
Been making a personal new tab just for fun with basic html stuff, but now I want a random video to show up every time I open a new tab. Been messing around with js but I can never get it to work. Does anyone know of any templates for randomizing js script where I can just put in the filenames and it would work? (.webm and .mp4 files btw)
>>
>>59132967
Get the solutions manual.
>>
>>59132972
Visual Studio
>>
I want to make an internet browser tab manager for all different internet browsers what is the best way to do this?
>>
>>59133064
I don't know. Good luck!
>>
>>59132972
notepad++
>>
>>59132972
Sublime
>>
File: 1.png (2KB, 404x404px) Image search: [Google]
1.png
2KB, 404x404px
What's an easy way to convert an ambiguous grammar (EBNF form) to a non-ambiguous grammar?
>>
File: Capture.jpg (106KB, 940x654px) Image search: [Google]
Capture.jpg
106KB, 940x654px
Trying to learn me some ruby on rails,

can someone tell me why it's rendering show.html.erb instead of goy.html.erb?

If you can see, the articles controller defines goy.

If i call articles/new, it does call the new.html.erb

If you call something other than new, it will render show.html.erb no matter what.
>>
>>59133132
harmful
>>
>>59132938
How do I edit the fgets function so that it conforms with:

while(fscanf(line,"%s", wordcheck)!=EOF)
>>
File: 1282560266903.jpg (78KB, 750x600px) Image search: [Google]
1282560266903.jpg
78KB, 750x600px
>>59133146
https://www.destroyallsoftware.com/talks/wat
>>
>>59133197
I don't want it to take from standard in I want it to take line as a string and process that?
>>
>>59133146
No, nobody here knows Ruby, not even Ruby
>>
>>59133173
ok, kiddo
>>
>>59133141
Remove left recursion and introduce precedence rules.
>>
>>59133026
not for C.
>>
whats a good resource for learning python?
>>
>>59133252
gonna remember this.

thanks anon
>>
File: 1458617689185.jpg (12KB, 236x265px) Image search: [Google]
1458617689185.jpg
12KB, 236x265px
What's the best language for making your own languages?
Haskell, OCaml or SML?
>>
File: 1419391357308.jpg (32KB, 596x285px) Image search: [Google]
1419391357308.jpg
32KB, 596x285px
Do you're use strong types or weak types?

https://www.destroyallsoftware.com/talks/useing-youre-types-good
>>
File: drank.jpg (48KB, 800x800px) Image search: [Google]
drank.jpg
48KB, 800x800px
About to graduate in May with a degree in Computer Science. I'm going to try to start working as soon as I can. How long until AI takes all my work? I'm hoping I get at least 10 years of employment... After that I guess I can fall back on my tech support skills.
>>
>>59133349
Ocaml is usually used for compilers for some reason. Sml is the nicest out of the three though but I think the ocaml implementation is better than any sml implementation out there sadly.
>>
>>59133349
Lisp.
>>
File: 1466559848718-fs8.png (40KB, 469x428px) Image search: [Google]
1466559848718-fs8.png
40KB, 469x428px
>>59133378
>How long until AI takes all my work

make sure you're the one writing the AI
>>
>>59133381
>SML
What's the best resource for learning it?
>>59133386
I don't like dynamic typing.
>>
>>59133433
>I don't like dynamic typing.
Learn to. It's the future.
>>
>>59133433
book Programming in Standard ML
or just skim trought the implementations documentation and find some example code to study.
>>
My Linux box isn't working right now. I need a way to convert .png to .pgm with P2 header. These can be made with ImageMagick (prebaked in most Linux distros):

convert input.png -depth 16 -compress None output.pgm


I'm on Windows, how can I do this? It's a PC at work, I can't VM or install IM on Windows.
>>
>>59133505

PS: Photoshop can save to .pgm but with P5 headers. There's no way to make a P2 .pgm with Photoshop.
>>
>>59133421
That works until the AI gets better at maintaining itself than humans are. At that point I think we're fucked as a species anyway though.
>>
>>59133473
Maybe for webshits and the like.
>>
GUYS PLEASE HELP

I got an assignment in a CS class a few days ago, I need to write an assembler for an imaginary CPU.

What the fuck do I do? I've never had a class on programming languages or compilers and have never written an assembler and the professor assumed that everyone knows how to make one.

What do I do lads?
>>
>>59133378
literally never.
>>
I want to make a messaging CLI app.

Could I use the raspberry pi I have lying around to act as a server that could send and receive messages? Or is there someway to do this with only two computers (OS X/Linux)
>>
>>59131431
except it sucks balls at everything else
>>
>>59133369
Type systems are a leaky abstraction.
>>
>>59133528
1) Did they specify what programming language you're supposed to use?
2) Did they specify what instruction set your assembler is supposed to target?
>>
>>59133535
Anon... It's already starting.
https://www.techworm.net/2017/02/microsofts-ai-deepcoder-learns-coding-stealing-others.html
>>
>>59133528
post the fucking assignment so i can solve it for you and win internet points
>>
>>59133433
If you use SBCL, you can get compile time type checking. But you can get it to be as dynamic as you want, so perfectly understandable.
>>
>>59133579
>1) Did they specify what programming language you're supposed to use?
It can be done in any commonly-used language, but the professor recommended Python

>2) Did they specify what instruction set your assembler is supposed to target?
Yes. From googling around, it looks pretty similar to "MIPS" assembly. Is MIPS is a common teaching architecture?

>>59133583
I don't want to post the full assignment, because I want to do it myself to learn, I just want tips on how to get started writing assemblers. It's supposedly a MIPS-based CPU, and the assembler can be written in any language.
>>
>>59133648
>Is MIPS is a common teaching architecture?
Yes.
>>
>>59131802
If you are looking at its value with printf, you need to use %u instead of %d
>>
Hey fellas, can you help me think recursively?
My professor assigned us a project due tuesday to give an n amount of permutations of a given set of characters. I'm fairly certain an array of chars would be the best way to do this so I can move stuff around with indices but when I try to actually write a recursive function... I just blank out. I've tried writing it on paper but the same thing happens. I can come up with a base case (just one letter to move) but then I'm not sure what next. This feels like such a bizarre technique and no teacher I've had can explain it well.
>>
>>59133648
>but the professor recommended Python
Drop it.
>>
how can it be that nobody has ever implemented statically typed multiparty session types with global type inference?
it's so EASY
>>
>>59131970
itoa takes a signed int, you need a function that works on unsigned, try snprintf(tempStr, 10, "%u", jump);
>>
>>59133691
Say you have a list of all the permutations for a list of n characters [c1, c2, c3, ..., cn].

How can you use that list of permutations to get the list of permutations for the list of characters [c1, c2, c3, ..., cn, c(n+1)]?
>>
>>59132805
okay I tried something and
>Error: target not supported by gdbserver.
goddamnit.
>>
>>59133588
>If you use SBCL, you can get compile time type checking.
explain further.
>>
>>59133349
Haskell
>>
>>59132427
Stalin can compile R4RS (-ish) Scheme to binaries that reliably outperform idiomatic C.
>>
>>59132805
gdbserver recieves commands from gdb. So when you type break into your gdb console, it will send that command to the gdbserver so it triggers a breakpoint on whatever hardware you are connected to. You might have to crosscompile gdbserver for whatever your target platform is, but gdb and gdbserver don't need to be compiled for the same platform, they communicate over a network protocol.
>>
File: spain-fs8.png (582B, 402x402px) Image search: [Google]
spain-fs8.png
582B, 402x402px
>>59133349
you can make your own languages in your own language
>>
>>59132773
No brakes on the rape train.
>>
>>59133779
No you can't.
>>
>>59133766
Why?
>>
>>59133197
fgets is fine as it is, use sscanf instead of fscanf, it operates on a string instead of a file
>>
>>59133798
>No you can't.

you can write a Java compiler in Java.

BTFO
>>
>>59133771
>Stalin
Wouldn't wanna use that garbage
>>
File: compilers.png (54KB, 899x737px) Image search: [Google]
compilers.png
54KB, 899x737px
>>59133813
https://github.com/Gabriel439/post-rfc/blob/master/sotu.md#compilers
>>
>>59133813
[Atto]Parsec.
>>
>>59133772
thanks anon. I just tried building gdb for the remote platform but it's not supported (>>59133760). so I guess I would need to implement the GDB machine interface in my program manually?
also wouldn't I need to compile gdb with --target=(remote-platform) so it can load the debugging symbols from the binary?
>>
>>59133838
Only because Java compilers already exist.
>>
>>59133779
How do you expect me to do this without a version in some other language?
>>
>>59133857
yes, and?
>>
>>59132427
Depending on the games you want.
gambic-c has lambdanative which let's you develop to desktop and mobile apps. It uses opengl underneath.

gambit-c and chicken have can easily inline c but they don't offer parallel threads.

bigloo has decent c interface, posix threads and good documentation how to compile for different platforms (windows, linux, mac, android, ios)
>>
>>59133754
nice meme anon

>>59133691
Look up examples of recursion problems. Break up your simple problem into a series of smaller problems. You're not really thinking about the problem correctly if n=1 is the base case.
>>
>>59133842
Then don't.
>>
>>59133866
You can't write a memelang compiler in memelang if you don't already have a way of compiling it.
>>
>>59133771
>>59133880
Thanks anons.
>>
I'm following DiveIntoPython3 website for learning. Am I doing right pythonists ?
>>
>>59133964
Python is wrong
>>
>>59133964
see >>59133981
>>
>>59133889
>nice meme anon
w-what?
>>
>>59133648
An assembler is much simpler than a programming language or compiler don't worry. Have a read of https://web.cse.ohio-state.edu/~crawfis/cse675-02/Slides/MIPS%20Instruction%20Set.pdf

Basically every instruction in MIPS is 4 bytes, and there's 3 different possible arrangements of bits based on the type of instruction. So for example with

ADDI R3, R4, 1

Rd = destination = R3
Rt = source = R4
Opcode = ADDI = ??
constant = 1

You find what opcode is Add Immediate, then put in the two register numbers, and then the immediate value 1 as a signed 16-bit number, following the layout given.
>>
this is you

https://www.youtube.com/watch?v=hk9SYguokjE
>>
>>59134034
Thanks for the tips, I'll read over that link.

I understand the MIPS ISA, but I have no idea how to go about building an actual assembler.

How would I detect that the user has typed in a label and not an instruction? How do I go through the code, remove any amount of bad formatting and assemble it properly?
>>
>>59133772
oh, and trying "target remote" with a tcp address throws an error:
(gdb) target remote localhost:23
Undefined command: "". Try "help".

do I need to compile gdb explicitly with tcp support maybe? I don't have a hardware serial connection, I'm trying to remote into a local VM.
>>
File: doggo.jpg (56KB, 593x305px) Image search: [Google]
doggo.jpg
56KB, 593x305px
regex guy here again with some questions

void read_string(string, regexp) {
while (true) {
read_string(string)
if (string.matches(regexp) {
print ("Illegal escape sequence detected!\n")
} else if (string.matches(regexp)) {
print ("Unterminated string literal detected\n")
}
}
}


valid escape sequences -> \f,\r,\\ and \"

examples i want/i'm trying to match
"\\  -> unterminated string literal

"\ -> invalid escape sequence (\) \n unterminated string literal

"\\\ -> invalid escape sequence (\) \n unterminated string literal


for the valid escape sequences i have this regex
 \\[^\\\"fr] 


can anyone help?
>>
>>59134180
>C#
that's where I stopped reading, "breh"
>>
>>59132972
Clion
>>
>>59134180
>sMaara
>>
File: 1487618733422.png (145KB, 500x517px) Image search: [Google]
1487618733422.png
145KB, 500x517px
>>59131250

> run a CPU intensive program I'm working on
> hear computer's fan speed up
> know it's done when the fan slows down

who /hacker/? pic related.
>>
>>59134282
Why do you format your posts like that, redditor?
>>
>>59134282
hahaha same bro
>>
>>59134291

reply
>>
>>59134293
>C#
that's where I stopped reading, "breh"
>>
>>59134293
>le
ebin reddit bacon narwal meighmeigh, friendo :^)
>>
>>59134282
>leave computer on while I go to sleep
>hear computer's fan speed up
>know that there's a bitcoin miner running

who /hacked/?

>>59134291
you're really keen on calling everyone out lately aren't you

you came here pretty recently didn't you?

could it be that you're from reddit?
>>
>>59133580
So far they have only created a proto Pajeet/webdev. Call me when the AI start generating optimised code.
>>
>>59134365
upvoted. that anonymous guy really makes me angry too!
>>
>>59134293
kys
>>
>>59134425
ah the broken-arms-switcharoo!!
>>
>>59134377
>I can't see the writing on the wall
>>
>>59134525
what wall?!
>>
>>59134525
Theories and prospects shall remain science fiction, until results are demonstrated.
>>
>>59134508
umm ok? lol
>>
>>59133580
>>59134377
>>59134525
As a person trying to break into the software development industry (I'm currently a student), what skills do you guys think will be in-demand when limited programming AI's like this will be more advanced and commonplace?

What kind of domain knowledge should one obtain to still be valuable when basic coding is handled by machines?
>>
>>59134572
>Theories
>shall remain science fiction
Learn to use your words correctly, idiot.
>>
>>59134603
Explain yourself.
>>
>>59134637
You should have paid attention in class.
>>
>>59134652
Not an explanation.
>>
>>59134586
guys?
>>
>>59134572
>Be me, factory worker in the year 1908
>Hear about Henry Ford's advances in streamlining factory work
>They'll never automate buildin' an automobile! That's crazy talk, mister!

This is how you sound.
>>
>>59134696
>guys?
i'm a girl.
>>
Still working on my twisty puzzle collection free game.
>>
>>59134670
You don't deserve one. The explanation is pretty clear if you aren't a complete retard (which you seem to be)
>>
File: thumbs.jpg (116KB, 600x410px) Image search: [Google]
thumbs.jpg
116KB, 600x410px
>>59134740
Looking nice, anon. Language?
>>
>>59134767
>Language?
OCaml.
>>
>>59134767
Javascript.
>>
File: icosahedron.png (138KB, 1000x1000px) Image search: [Google]
icosahedron.png
138KB, 1000x1000px
we triangles now
>>
Is christianity turing-complete?
>>
I hate C with a fiery passion. What language should I learn now?
>>
>>59134363

>2017
>doesn't know what ironic shitposting is
>>
>>59134795
and my axe
>>
>>59134791
Probably something really easy, since you can't handle C. I hear python is good for entry-level programmers.
>>
>>59134111
What are you trying to do?

'read_string' suggests you're trying to implement a parser of some sort. If what you're trying to parse is not a regular language, then regular expressions are not suitable.
>>
>>59134710
I never said it won't happen, retard. What I am saying is that their current progress in emulating the bottom of the barrel koders does not mean they will ever achieve parity with competent programmers producing optimised code. They might, but there is no indicator to that yet.
>>
All right, I give up.

Why does this seem to get stuck in an infinite loop:

MineSweepState::MineSweepState(int size,int number_of_mines) :
gridsize(size), //Type int
difficulty(number_of_mines), //Type int
has_lost(false), // Type bool
revealed(size*size,false), // Type std::vector<bool>
mines() // Type std::set<std::pair<int,int>>
{
while (mines.size() < difficulty ) {
mines.insert(std::make_pair(std::rand() % size , std::rand() % size));
}
}

>>
>>59134842
>C++
stopped reading right there.
>>
>>59134842
It's OOP. Getting stuck in obfuscation is a feature.
>>
>>59133234
I was told it was super popular and you could make big cash.

Why are STEM peers always lying to me.
>>
>>59134810
C is a novice programming language
>>
>>59134826
I'm trying to detect errors in strings, with the final goal of being used in a compiler
example
class Program {
public static void main(String[] args) {
String a = "\\\;
System.out.println(a);
}
}

this would throw
Program.java:4: error: illegal escape character
String a = "\\\;
^
Program.java:4: error: unclosed string literal
String a = "\\\;


this is what i'm trying to do. given a string detect this errors, like i exemplified before
>>
>>59134842
How large is difficulty? Also print mines.size() each iteration.
>>
>>59134893

read the file char by char

when you find a parentheses add one to a counter

then detect if it's an even or an odd number
>>
>>59134892
Yeah, I know that. What anon was saying is that he's too poor of a coder to even handle C. So naturally, he needs something even easier. Is your reading comprehension not very good?
>>
public static void Main()
{
int rAmount = LettersinaWord("hamburger", 'r');
int eAmount = LettersinaWord("hamburger", 'e');
Console.WriteLine("There are " + rAmount + " r's in the word 'hamburger'");
Console.WriteLine("There are " + eAmount + " e's in the word 'hamburger'");
}
public static int LettersinaWord()
{

}


I'd really appreciate if someone could do this for me (C#). Thank you in advance.
>>
>>59134935
the thing is: i'm supposed to do that with regex and states (flex).

that c-style code i posted was just pseudo-code
>>
>>59134907
Difficulty should be strictly smaller than size, I'm calling it as
gridsize(8),
gameState(gridsize,7),


In the constructor of the GUI object.
>>
>>59134893
If you're trying to write a compiler, then you're attempting to parse a language higher in the Chomsky hierarchy than is appropriate for regular expressions.

Here is the standard link to post when people attempt this:
http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags
>>
>>59134943
I don't see python being any easier than C at all, writing 40 more lines of code than a python counterpart doesn't make C """"hard to handle""""
>>
I need to learn C++. I know C and OOP languages. What are the C++ essentials I'm missing based on what I know?
>>
>>59134959
No problem!
>>
>>59134978
No.

i'm simply trying to parse Java code.
>>
>>59135028
>Java code
Exactly.
>>
>>59135003
Haven't do Sepples in ages, but I remember the iterators, streams, multiple inheritance, smart pointers, templates, RAII, and that's it.
>>
>>59134987
Somehow
print "hello world"

Is not more simple than
#include <stdio.h>

int main(){
printf("hello world");
return 0;
}


Hmm... Well meme'd anon!
>>
>>59134966
That doesn't really answer how big difficulty is but my guess is that insert() fails because size == 8 so mines can only contain 8 unique keys.
>>
>>59135053
Goes to show what a piece of shit C(ancer) is.

C is a garbage language that plagues the software industry.

Also your code is not finished, newbie. Here, let me help:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

extern int errno;
extern FILE *stdout;

int main(int argc, char** argv)
{
errno = 0;

int err = printf("Hello World\n");

if (err < 0) {
return EXIT_FAILURE;
}

err = fflush(stdout);

if (err < 0 || errno != 0) {
return EXIT_FAILURE;
} else {
return EXIT_SUCCESS;
}
}
>>
>>59134959

halp
>>
>>59135053
That's just being needlessly verbose. It's not "difficult", it's just a time-sink
>>
>>59135115
*sigh*
#include <stdio.h>
#include <errno.h>

extern int errno;
extern FILE *stdout;

int main()
{
errno = 0;

int err = puts("Hello World\n");

if (err < 0) {
return EXIT_FAILURE;
}

err = fflush(stdout);

return !(err < 0 || errno != 0);
}
>>
>>59131416
Why would anyone use C?
>>
>>59135155
No, python is being disingenuous by hiding what is actually going on. You might be able to write the second code snippet just as easily by copying what's in a tutorial, but to understand what is going on is much more difficult.

>>59135115
>Shits on C, can't write C code
No surprises there I guess.
>>
>>59133146
Ask /wdg/.
>>
>>59135216
>Defends C, can't write C code
No wonder coming from an average C toddler. Go back to your program that prints 1 2 3 thrice if the input is 3
>>
>>59135201
To force oneself to use neither classes nor lambdas.
>>
>>59134959
>>59135152

I actually managed to do it (yay me). But I have a problem where it doesn't count capital letters.

Any tips?
>>
>>59135115
>extern int errno
>errors from printf
>not using err(3)
>>
>>59135028
Java is not a regular language. You cannot parse it using regex.
>>
>>59135216
>hiding what is actually going on
It's upto you if it remains hidden or not
>>
>>59133349
If you don't know any MLs, start with SML. Do not learn Haskell until you understand modules. Typeclasses aren't good enough, and if start with Haskell you may never grok the alternative.
>>
>>59135249
>errors from printf
son, ...
>>
>>59135270
runt
>>
Why are you guys obsessed with this pictures of anime little girls holding programming books?
Isn't it weird to be attracted to anime at your age?
>>
>>59135252
that's why i said i have to use regex and states
>>
>>59135292
Welcome to /dpt/.

Please don't talk to the anime posters, they'll only respond with more anime images.
>>
>>59133381
>I think the ocaml implementation is better than any sml implementation out there
Depends on the kind of "better" you have in mind. MLton is one of the most impressive optimizing compilers out there (it makes your code go crazy fast), but it isn't as user friendly as OCaml.
>>
File: karen haskell.png (818KB, 1280x719px) Image search: [Google]
karen haskell.png
818KB, 1280x719px
>>59135292
no
>>
File: 1485900094520.jpg (26KB, 274x321px) Image search: [Google]
1485900094520.jpg
26KB, 274x321px
@59135292
>>
>>59135234
The Linux source code itself doesn't catch errors from printf. Clearly I'M the one that's being retarded. Oh, wait.
>>
What are lambda functions?
Are they functions that return functions?
I don't get it.
>>
>>59135247
Downcase the string and then check. Or check for both uppercase and lowercase.
>>
>>59133505
>>59133521
http://gnuwin32.sourceforge.net/downlinks/netpbm-bin-zip.php
No installation required.
>>
>>59135115
int err = printf("Hello World\n");
>>
>>59135382
can you do it for me?

i have this party i have to go in 20 minutes and it would be fine if some nerd could write me the solution
>>
>>59135374
Functions without names.
>>
>>59133771
Don't forget that Chez is now FLOSS. It is faster than Stalin in many cases and supports R7RS.
>>
>>59135369
That's because Linus is a newbie that made shitty CoW exploit slip.
>>
>>59135374
They're just anonymous functions, (functions without a name).
>Are they functions that return functions?
Those are High-order functions, i.e: A function that accepts functions as parameters, or returns one. Take for example C's qsort function.
>>
>>59135415
2bad
>>
I'm going through the sicp, and in the first chapter, they told me that Fibonachi programm have exponentional grow in time, and linear grow in space. While I can figure out time's consuming, I dont get why space is linear. I mean you in order to compute fib(n), you gotta remember fib(n-1) + fib (n-2), and it expands as (fib (n-2) + fib(n-3))+ (fib (n-3)+fib(n-4)) and so on, you gotta remember 2x more addition every reduction steps, and it grows as 2^n, which is exponent.
(sorry for my english)
>>
>>59135443
seriously bro?
>>
Spent two days trying to make a DLL in C and gave up because I have no fucking clue why it's outputting the wrong data.

Spent 5 minutes making a console application out of the same code. It works perfectly.
>>
>>59135420
>Linus is a newbie
Alright, this has been fun. I feel bad for letting myself get trolled by you for so long. Enjoy your retard delusions anon, you are a genius and everyone else is shit.
>>
>linux uses \n
>windows uses \r\n
why
>>
>>59135485
legacy
>>
>>59134791
Free Pascal. It's low-level like C but with a good type system and basic OO if you want it.
>>
>>59135419
I have not found it to be faster than Stalin, but yes, it is also worth recommending.
>>
>>59135485
>linux uses \n
>windows uses \r\n
>old macs used \r
>>
>>59135474
Yes, he's a "newbie that cannot handle C". Do you lack "reading comprehension"?
>>
>>59135485
retardation
>>
>>59135460
> remember 2x more addition
As far as Big O notation goes, O(2*n) == O(n)
>>
>>59135460
>expands as (fib (n-2) + fib(n-3))+ (fib (n-3)+fib(n-4))
You don't have to remember those values, though, it's enough that you remember n-1 and n-2.
>>
>>59135485
The \r is optional. Any non-shit program can function without it.
>>
>>59135460
Not with memoization. Store the previous calculations in a table and look them up when needed.
>>
>>59135415

So you guys hate people who write C# because they get laid and have a stable job?
>>
>>59134966
Oh, I managed to fix it, but I really don't understand why it worked. I changed the constructor call to

 
gridsize(8),
gameState(8,7),
>>
>>59135526
C# is fine. The only reason I hate it is because it's based of C(ancer)
>>
>>59135419
Does it? I thought it was only at R6RS.
>>
>>59135548
on* C(ommunism)
>>
>>59135546
Did you read this?
>>59135072

std::set has unique keys, and since your keys are std::rand() % size, and size is 8, then you can only have 8 keys. If difficulty is 8 or more then insert() will fail.
>>
I have this really interesting program that uses a while loop to determine how many letters a word has but it doesn't detect the letter if it's upper case.

How do I make it detect upper case letters as well? (C#)
>>
>>59135616
Post code.

And brace yourself.
>>
Does anyone here know Django?
How do I access a specific file(or it's filename) that was input via a imagefield in models.py?
>>
>>59135616
The same way we already told you, you retarded faggot.
>>
>>59135616
Convert every letter to lowercase before checking it.
>>
>>59135648
>>59135659
>>59135628
can you do it for me?

i have this party i have to go in 10 minutes and it would be fine if some nerd could write me the solution
>>
>>59135669
2bad
>>
Is there a place where I can get the java with netbeans textbook?
>>
>>59135463
>DLL
Found your problem. Windows libraries are a clusterfuck.
>>
>>59135669
Sorry, busy masturbating.
>>
>>59135704
Yes.
>>
>>59134778
>using javascript outisde the browser
wtf is wrong with you
>>
>>59135752
pls don't bully, I bought the book I just want it on my computer as well.
>>
>>59135155
It helps you understand what's actually going on under the hood

there's no ambiguity with C which is why people like it. you have to be explicit for things that you wouldn't in other languages

you don't say
>go to wall
>turn on the light

you gotta say
>stand up from chair
>approach wall by walking
>stop in front of light switch
>flick light switch with right hand
>>
>>59134092
Look into writing a lexer (aka tokenizer) to break your source string into discrete units represented by types, so

label1: ADDI R1, R3, 5

goes to

Identifier('label1')
Colon
Identifier('ADDI')
Register(1)
Comma
Register(3)
Comma
Integer(5)

your lexer would discard comments, not making them into tokens.
Then from the token stream, you see an identifier, then if the next token is a colon that makes a label which you record, otherwise you expect it to be an instruction
>>
>>59135777
>there's no ambiguity with C
And yet you just posted printf() trash that produces exceptions just like any other C programs
>>
File: 1486429712136.jpg (123KB, 410x410px) Image search: [Google]
1486429712136.jpg
123KB, 410x410px
>>59135777
>there's no ambiguity with C
>>
>>59135774
Get raped and kill yourself, you retarded fucking faggot sack of nigger shit with down syndrome.
>>
>>59135822
this reply again?

its getting old
>>
>>59135836
So is your mom. She's probably going to die in her sleep tonight. Drink bleach, shit stain.
>>
>>59135822
OP here. I just started programming a few weeks ago, and just started coming to these threads a week ago. Is this a meme?
>>
>>59135003
Read Accelerated C++
>>
>>59135669
I'm watching anime right now, sorry mate.
>>
>>59135851
you have to go back
>>
>>59135861
Yes. We perpetuate only the finest memes in /dpt/.
>>
>>59135786
Thanks

I'll look up some resources on making a lexer
>>
I'm writing an implementation of the monte carlo tree search with a twist for my own purposes, and am a little stuck up on how to do the backpropagation stage.

Should I just use pointers pointing to the previous node or can I do some sort of memory address manipulation in order to keep track of the nodes visited, and then go back up and update the weight?

I'd be glad for any suggestions, thanks!
>>
>>59134791
BASIC

>>59134795
>>59134808
>LE JOAK IS ON LE YOU I WAS ONLY LE PRETENDING TO BE LE RETARDED

>>59134935
No, don't do that, that's retarded. Just increment the counter on each '(' and decrement it on each ')', if it ends at anything but zero you have unmatched parentheses.

>>59134987
Python is easier to reason about because the constructs are at a higher level of abstraction. For example you don't need to really worry about pass-by-value vs pass-by-reference, format strings, or array decay.

>>59135115
C is fine if you use it for what it's meant for - lightweight systems programming for writing operating systems and shell utilities. Sometimes you don't WANT all that fancy error-detections stuff brought in, because it just bloats your binaries. C gives you the option to leave that stuff out when you don't need it. Of course, putting it in when you DO want/need it does require boilerplate code, but then you can always use a library, or just switch to a proper applications language that supports that style of programming.

>>59135155
No, that's not verbose at all, the only way it could be even less verbose is if you eliminate whitespace and make it a one-liner, but that wouldn't change the number of statements you need. Technically, I think it would have to be even more verbose, some older C compilers don't consider int main() to be a valid signature, as that would potentially allow the runtime to overwrite the stack frame of main() with arguments, since you need main(void) to specify that it cannot take any arguments, () was essentially the K&R version of varargs.

And omitting return 0 won't work before C99, it would just return whatever's in eax at that point, so behavior is undefined.

>>59135198
>>59135115
Are the definitions for errno and stdout really neccessary? Aren't they provided by the respective headers? And isn't errno guaranteed to be 0 initialized?

>>59135201
For writing operating systems.
>>
>>59135803
I didn't post that
I'm just playing devils advocate for C here


I can look at structures in C and know exactly what is going on right away, but in OOP languages a program doing the same thing would be harder to follow
C/C++ just makes more sense to me, and a lot of people feel the same way for similar reasons
>>
>>59135865
I should have specified, I need at least C++11, preferably 14. I'm gonna read through Stroustrup's book eventually, I just want to take a quick glance at some topics now.
>>
>>59135613
Keys are pairs of two std::rand() % size . So the max number of keys is 64, or more generally size squared.

Infinite loop seems to be because of undefined behaviour in the initializer list.
>>
>>59135918
I know what you're trying to say. You have to be very explicit in C. Because of things like static typing and a lot of manual management of... everything really. But "no ambiguity" is a really bad phrasing because C is the king of undefined behaviour.
>>
>>59134791
I'm learning D. It's fairly decent in comparison to 'c'. However I still get the reminiscence that makes me shiver with anger at seeing 'c' style syntax.

>>59135917
>BASIC
looks pretty comforting. Thanks
>>
>>59135960
Undefined behaviour is not "ambiguity". It's "don't do this, otherwise your program is invalid".
>>
>>59135963
Learn python it was made for people like you.
>>
Nothing is more cringey than (((C)))
>>
>>59135975
People that want productivity? People that can produce actual software?

Sign me up. I'd actually use it but the performance is out of my range of consideration.
>>
>>59135972
What you're saying would be valid if those things actually produced warnings or errors.

>>59135991
OK buddy.
>>
>>59135659

I thought I did that but it doesn't seem to work. How would you do it?
>>
>>59136010
>What you're saying would be valid if those things actually produced warnings or errors.
A lot of them do. But some of them would be extremely hard for an implementation to check for.
>>
>tfw CS class
>professor takes routine class test and wants us to implement some algorithm in C
>Plebs lose their shit but can't finish the task in time
>while I write it both in C and Rust and show professor how C is trash
>"emerging language XD"
>>
>>59136064
His name? Albert Einstein
>>
>>59136064
wow, just like that?

no way
>>
>>59136064
Did CTR recycle into Mozilla's task force?
>>
>>59136083
I voted for trump and I hate blacks, spics, jews, mongoloids and everyone else :D
>>
>>59136083
Donald is the best
I wanna suck his dicks
I love his red face and I love his juicy tits
>>
>>59135234
#include <stdio.h>

int main(int argc, char *argv[])
{
int n, i, j;
if(argv[1] == NULL) {
fputs("kys", stderr);
exit(EXIT_FAILURE);
}
n = atoi(argv[1]);
for(i = 0; i < n; ++i) {
for(j = 1; j <= n; ++j) {
printf("%d ", j);
}
putchar('\n');
}
return(EXIT_SUCCESS);
}


>>59135369
printf isn't even available in kernel code.

>>59135374
It's just an anonymous function. If you're familiar with JS, you can write functions in the following style:

 var add = function(a,b) { return a + b; }


That's technically using a lambda, you're declaring a variable, and assigning a "function literal" to it. By itself, that function literal has no name, you're merely "binding" it to the name add. And JS actually has some functions that take a function as an argument, so you can just type in a lambda function literal there too, rather than have to use the explicit function pointer stuff like in C.

>>59135518
That's still retarded, because literally nobody uses plain \r anymore, what everyone uses is the Unix \n, which the Windows standard text editor (notepad) can't handle, so basically anything you download in plain text form on Windows ends up being a bunch of gibberish.

>>59135803
Printf doesn't produce ``exceptions". It may produce ``traps", but those cause your program to hang BEFORE the function returns, so checking return values won't prevent that. And since stdio is just a wrapper around OS I/O functions, chances are a failure is due to your operating system, not the C library.
>>
File: 1456405045623.jpg (13KB, 499x499px) Image search: [Google]
1456405045623.jpg
13KB, 499x499px
>>59136138
>return(EXIT_SUCCESS);
>doesn't include stdlib

C toddlers lol
>>
>>59136138
>Printf doesn't produce ``exceptions"
try redirecting that into a bad file
>>
>>59136154
C babbies can't even average two integers lmao
>>
>>59135960
Undefined behavior is the exact opposite of ambiguity. It teaches you to avoid ambiguity because you can't count on "do what I mean" behavior.
>>
>>59136154
>>59136167
return (a+b)/2;
>>
>>59136212
TOP KEK
>>
>>59135956
No, keys are only the first part of a std::pair. The map stores key-value pairs.
>>
>>59135917

except we weren't talking about parentheses we were talking about quotations dumbfuck
>>
>>59136154
gcc -DEXIT_SUCCESS=0 -DEXIT_FAILURE=1 main.c


>>59136167
What's that supposed to mean? Redirection is an OS feature, if that causes "exceptions", that's the operating system's fault, not printf's.

>>59136189
float average(int a, int b)
{
float c = a + b;
return(c / 2);
}
>>
>>59136282
>float
>>
File: It's time to stop shitposting.jpg (32KB, 519x480px) Image search: [Google]
It's time to stop shitposting.jpg
32KB, 519x480px
>>59135115
>int err = printf("Hello World\n");
>>
>>59136282
Wow, retard.
>>
jesus christ this thread is cancer
>>
>>59136295
C brainlet pls
>>
>>59136282
>gcc -DEXIT_SUCCESS=0 -DEXIT_FAILURE=1
lel instead of defining in the program itself C toddlers now define in compiler instruction
>>
>>59136292
The situation really doesn't call for the precision of a double, and there's no other way to get an intuitive average of say 2 and 3.
>>
>>59136282
Don't waste your time. Retards have been working extra-hard (for free) shilling against Intel and C these last few days.
>>
File: 1468618167499.png (14KB, 333x293px) Image search: [Google]
1468618167499.png
14KB, 333x293px
>>59136349
gee I wonder who could be behind this post
>>
>>59136342
I made an honest mistake leaving it out, but GCC does let you get around that.
>>
New thread:
>>59136377
>>59136377
>>59136377
>>
>>59136365
>an honest mistake
Let's wait C defense force's officio response

"LUL U MADE A MISTAKE U CAN'T EVEN HANDLE C XDXDXDDDD THOSE SECURITY BUGS ARE FROM PEOPLE JUST LIKE YOU :DDD"
>>
>>59136404
You do know that's the kind of mistake that any compiler would inform you about? I was just posting some shitty code written in 3 minutes in response to a post on an imageboard.
>>
>>59132972
friggin emacs bruh
>>
>>59136282
The worst avg I've ever seen
How about
return ((a+b/2);
>>
>>59136514
How about the one where you shift them both before adding?
>>
>>59136514
That would be literally even worse, since / has higher precedece than +, and b/2 does INTEGER division. So average (10,15) would give 17. Which I'm pretty sure isn't what you want.
>>
File: currencydistributor.jpg (67KB, 941x541px) Image search: [Google]
currencydistributor.jpg
67KB, 941x541px
What's a sophisticated solution to this? I can only think of a control structure such as an if else statement.
>>
>>59137058
You clearly haven't read your SICP.
>>
>>59137058
list of values sorted from highest to lowest.
you recurse trough it and pass around the inserted value and decrement it each function call.
you called the recursion result into list.
>>
averaging two ints in C is actually a good interview question

a smart person should be able to deduce the solution
>>
>>59137242
I just import lua.
>>
>>59137152
I don't get this answer.
>>
>>59137058
This is me again. What I came up with.

#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
int input;
int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0;

cout << "Enter $ amount as integer form: ";
cin >> input;

if (input >= 500) {
a = input / 500;
input = input % 500;
}

if (input >= 100) {
b = input / 100;
input = input % 100;
}

if (input >= 50) {
c = input / 50;
input = input % 50;
}

if (input >= 20) {
d = input / 20;
input = input % 20;
}

if (input >= 10) {
e = input / 10;
input = input % 10;
}

if (input >= 5) {
f = input / 5;
input = input % 5;
}

if (input >= 1) {
g = input / 1;
input = input % 1;
}

cout << "500: " << a << endl;
cout << "100: " << b << endl;
cout << "50: " << c << endl;
cout << "20: " << d << endl;
cout << "10: " << e << endl;
cout << "5: " << f << endl;
cout << "1: " << g << endl;


system("pause");
return 0;
}


What's a better way to do this?
Thread posts: 334
Thread images: 30


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.