/dpt/ - Daily Programming Thread

old thread: What are you working on, Sup Forums?

First for D

What tool do you use for a blowjob?

Thank you for posting Hime. Have some feminine code as a reward :
use std::mem::transmute as crossdress;

struct Boy;
struct Girl;

fn main() {
let hime: Girl = unsafe { crossdress(Boy) };
}

Should I learn Python or C?
Which one is more useful?

python

>Which one is more useful?
Python, but learn C If you want to learn programming.

please rate my fizzbuzz
#include
#include
#include
pthread_mutex_t lock;

void* fizzbuzz(const void* n)
{
pthread_mutex_lock(&lock);
int i = n;
if(i%15 == 0){
printf("fizzbuzz\n");
}
else if(i%5 == 0){
printf("buzz\n");
}
else if(i%3 == 0){
printf("fizz\n");
}
else
printf("%d\n",n);
pthread_mutex_unlock(&lock);
}
int main(void)
{
int threads = 0xFF;
pthread_t thread_id[threads];
int i;
int j[threads];
for(i=1;i

>Python, but learn C If you want to learn programming.
Would I not learn programming from Python?
Okay, I'll get the meme C book

Learn Python first, then C to better understand how things work under the hood, and in case you need performance.

pls respond

Assembly programmers

You would, but you'll miss out on all of the low level concepts such as pointers and addresses.

Also C is the lingua franca of computer science. If you're a programmer who doesn't know any C you won't even be taken seriously. Again, if you want to program for the sake of making simple scripts and small projects then look no further than Python, it's the best language for "getting shit done". But if you want to become an actual programmer then you must learn C.

>doesnt initialize mutex lock
i'd say it's about deadlock/5

I would say that C is the lingua franca of software engineering, but not computer science.

ok, playing music works now

now i just have to implement proper pausing (instead of stopping), a seek bar, skipping to next/previous, and so on

and of course improve looks

>If it's stupid but it works, it's not stupid.

is this valid in programming? do you care?

Fizzbuzz is too easy.
Everyone should be able to implement a naive substring search.

If not, you shouldn't be allowed near a computer.

Yeah no. GCC and other compilers are so advanced today that there's no point in programming in Assembly except for very niche situations. In general properly written C/C++ code will run just as fast.
If the top of the food chain is simply the most low level language then it stops at C, everything else is a meme.

it is completely valid unless it's so stupid it slows everything to a crawl (like doing intense i/o in every iteration of a loop or something equally retarded)

i noticed that many newbies are afraid of sharing their code because they're not confident and think that people will laugh at their mistakes, but if a program does what it's supposed to do and consumes a reasonable amount of resources, and is moderately fast, it's great in my book

A search for... all the substrings in a string?

is using multiple contexts with opengl useless except for data transfer and having multiple windows?

like if you want to render to a shared texture (let's say it's an expensive shader and you don't need the result immediately) and the opengl implementation is single-threaded then it will just be the same as (or a bit slower than) doing single-threaded rendering?

Probably means if string X is in string Y

Shits easier than fizzbuzz

You mean UB/5

I agree, but Python is still very useful and more friendly for beginners.
It can also introduce them to OOP and functional programming once they have a good grasp of procedural programming.
The best thing is to learn both. If you aren't familiar with at least 3 languages using different paradigms and features, I would say that you aren't a real programmer.

Audio devs often use SSE/AVX instructions and the like to tighten their processing loops, and I'm sure game dev do the same, but yeah, it's generally just inline assembly in the context of a C/C++ program.

Oh, that's easy. It's just if sub in str:.

rate me /dpt/

bool charSearch(char* toSearch, char* term)
{
int len = strlen(toSearch);
int termLen = strlen(term);

for (int i=0; i

if you found it already, just return true immediately, you don't need any breaks in that loop.

Nice.

fn contains_substr(to_search: &str, to_find: &str) -> bool {
to_search.contains(to_find)
}

>creating variables inside a loop

no

what the fuck, fix those braces

char *strstr(const char *haystack, const char *needle)
{
size_t h_len = strlen(haystack);
size_t n_len = strlen(needle);
size_t i, j;
for (i = 0; i < h_len; i++)
{
size_t found = 0;
for (j = 0; j < n_len; j++)
{
if (i + n_len < h_len)
if (haystack[i + j] == needle[j])
found++;
}
if (found == n_len)
return &needle[i];
}
return NULL;
}

looks cool.

> Not using regex

>what is an optimizing compiler

good but you need to pick up a more conventional code style and also it can be cleaned up a bit like said

Thank you bros, next week I will probably post some binaries and code too

actually nvm you need to check the whole thing and not return immediately so keep it as it is

const char* strstr(const char* haystack, const char* needle) __attribute__((leaf, nonnull)) {
size_t i;

for( i = 0 ; *haystack && haystack[i] ; haystack++ )
for( i = 0 ; haystack[i] == needle[i] ; i++ )
if( !needle[i] )
return haystack;

return NULL;
}

the outer loop should go to len - termLen so you don't go out of bounds

Fug.

for( i = 0 ; haystack[i] == needle[i] ; i++ )
if( !needle[i + 1] )
return haystack;

bool is_substring(char* sub, char* str)
{
char *tmpsub, *tmpstr;
for(;*str != 0;str++) {
if (*str == *sub) {
tmpsub = sub;
tmpstr = str;
while (*tmpsub != 0) {
if (*tmpsub != *tmpstr) goto resume_main_loop;
tmpsub++;
tmpstr++;
}
return true;
}
resume_main_loop:;
}
return false;
}

This is very ugly, but it works

How would you reconcile the overlap between regex and file globbing?

>goto resume_main_loop
How about just continue?

Didn't see inner loop because your indent is shit.

Because it would return true otherwise, I don't know to structure this in another way.
Sorry btw for the fucked up indentation, my Emacs config use tabs instead of 8 spaces for some reason.

it should only return if found, otherwise it should keep searching

How would one loop through an int value in c#?

Please show the implementation or just describe how you would do it.

imagirlbtw

And once again, this doesn't do what the example does and is still worse

If you mean look at each digit in a multi-digit int, like 12345, just take % 10 and store the answer, divide the number by 10, rinse and repeat until the number is 0.

can someone say this in english pls im a girl

>want to make toy prog language
Should I call it EvilC?

If you take modulo 10 of a number 12345, you get 5. If 12345 is an int as you said, dividing it by 10 will give you 1234. If you take modulo 10 of 1234, you get 4, and so on and so forth until your number is 0 and you break the loop.

wouldn't that just be regular c?

what's a modulo?

I am hoping to use the MPQA Subjectivity Clues tff file to use as a dictionary of negative and positive words in a basic sentiment analysis tool I am making in Java. How would I parse the file into prefix trees in my code?

type=strongsubj len=1 word1=scrupulously pos1=anypos stemmed1=n priorpolarity=positive
type=strongsubj len=1 word1=scrutinize pos1=verb stemmed1=y priorpolarity=neutral
type=strongsubj len=1 word1=scrutiny pos1=adj stemmed1=n priorpolarity=neutral

what's a google?

Google it you stupid twat.

>If you're a programmer who doesn't know any C you won't even be taken seriously.
lol

these are not me!!!

post feet to prove you're a girl if you want more help

solve my problem for me and i will consider it user

It gives you the remainder of a integer division.
>>> print([n % 3 for n in range(1, 7)]) # n = [1..6]
[1, 2, 0, 1, 2, 0]

#include

main()
{
int c = EOF;

printf ("%3d\n", c);
}

Is this faulty in any way? Will the concept of EOF become more clear as I progress through the meme book?

Is modulo useful for anything other than clamping a number to a certain number range?

see

>that guy who doesn't compile with -fno-exceptions -fno-rtti

What's his story?

First thought for another use is prime factorization.

c'mon user implement it for me please!

fizzbuzz

Learn Haskell first

tits first

>implying you're actually a girl
>implying it's hard to find the solution on google

> It gives you the remainder of a integer division.
Not always.

What do you wanna do with the digits though ?
You didn't tell.

Liars get no code.

What is love?

check em

Anyone with experience using the BASC_py4chan python wrappers to use the Sup Forums API?

I'm trying to get all the links and the files of a thread in two separate lists within a loop, but this throws an error:

def get_img_links(self, thread, _res):

# File = high, width and file
board = basc_py4chan.Board('g')
board.get_thread(get_id(thread))
links = []
zsfile = []
post = 0
try:
for file in threadid.files():
links.append(file)
zsfile[post] = File(threadid.posts[post], file)
post += 1
except Exception as e:
print("Error: " + str(e))
Run.restart(self)


Error: list assignment index out of range

watdo?

check = lambda n: "checked" if n%10 == n/10%10 else "kys"

whoops, forgot code tags.

def get_img_links(self, thread, _res):

# File = high, width and file
board = basc_py4chan.Board('g')
board.get_thread(get_id(thread))
links = []
zsfile = []
post = 0
try:
for file in threadid.files():
links.append(file)
zsfile[post] = File(threadid.posts[post], file)
post += 1
except Exception as e:
print("Error: " + str(e))
Run.restart(self)

Would it be better to use a prefix tree or hash table, if the structure will be formed at the start of the program, and read from hundreds of times a minute?

pleb
#include
#include

bool is_substring (const std::string &sub, const std::string &str) {
const size_t sub_size (sub.size ());
if (sub_size == 0) {
return true;
}
const size_t str_size (str.size ());
std::set state { 0, };
for (size_t i (0); i < str_size; i++) {
const char c (str[i]);
std::set next_state;
for (size_t j : state) {
if (sub[j++] == c) {
if (j == sub_size) {
return true;
}
next_state.insert (j);
}
}
state = next_state;
state.insert (0);
}
return false;
}

>zsfile[post]

you cant do that

More verbose than C

Show me the same in C.

I think a string comparison + a lookup in a hash table would be less expensive.

see

How dare you compare your algorithm and mine?

Why don't you just call the standard library's "Contains()" method?

Fucking nerds, wasting your time doing simple bullshit that's already built-in.

Okay, but my code is C89 compliant and doesn't need the stdlib if you add
#define bool int
#define true 1
#define false 0

It's just not the same algorithm. I could write my code in C89 but I would have to re-implement sets, I am too lazy for that.

pleb
#include
/**
* @brief is_substring
* @var sub
* substring
* @var str
* string
* @return
* true if substring is part of string.
*/
bool is_substring( const std::string &sub, const std::string &str) {
size_t found = str.find(sub);
return found != std::string::npos;
}

>size_t
>not std::string::size_type

F-

it's a problem solving exercise which is simple enough to do in a minute or so. the point is not to achieve the result YOU FUCKING RETARD. when you get past the code monkey shit you work with you'll actually have to do some real programming

>not auto

Where is microsounds, AkariBBS has been down for a while

>real programming
>using the standard library to implement something that's in the standard library

Also fucking lol at
>the point is not to achieve the result

That's immediately apparent when some faggot makes a function that averages two integers, or any other useless trivial bullshit that gets done here constantly.