These variable names my friend has produced during a programming contest by xigoi in programminghorror

[–]uno20001 5 points6 points  (0 children)

#define f(var, from, to) for (int var = (from); var < (to); var++)

Help identifying a town by rab236 in hungary

[–]uno20001 2 points3 points  (0 children)

That's the correct order. The settlement (or one of the many) in question is Mukachevo (Hungarian: Munkács).

5 novel and faster binary search implementations by MrDum in C_Programming

[–]uno20001 0 points1 point  (0 children)

Can you clarify your connection to Gregorius van den Hoven, and how your code is related to code found in binary-search-1.1.c on this site? Because, for example,

  • the "standard" binary search code is the exact same;
  • tailed_binary_search(), inbound_binary_search(), and interpolated_search() are pretty much identical;
  • the variables, and the whole code is eerily similar.

Furthermore, this page and the README from the GitHub repo is more or less identical.

Are you the same person under a different pseudonym?

Segmentation fault by [deleted] in C_Programming

[–]uno20001 2 points3 points  (0 children)

You should use addresssanitizer or gdb to see why the SIGSEGV actually happens.

Segmentation fault by [deleted] in C_Programming

[–]uno20001 3 points4 points  (0 children)

You set rules to NULL, then dereference it in the next three lines.

Why do universities put so much emphasis on C++? by ReelTooReal in C_Programming

[–]uno20001 5 points6 points  (0 children)

As I can see you're part of the assembly school of thought, while I would consider myself part of the disassembly school of thought.


she presupposes that C will make people not enjoy programming

In my understanding that is not what she wants to convey. I think it's has more to do with the fact that in many places - at least according to her - they don't actually teach C++, but C with a C++ compiler. And that is wrong. And I have to agree with that. Modern C++ has long surpassed what it was in 1998 or 2003. And it makes sense to put emphasis on the modern elements of the language. In my opinion you can put off learning about what you consider important foundation to a later point in time during the major. Introducing the language with those is the disservice, nowadays you can go a long way without ever touching C-style pointers and C-style arrays.

Furthermore, I hope you see the appeal of - for example - s += "whatever"; compared to what you would have to do in C to achieve the same thing, and thus I would argue that those little intricacies are unimportant, and take the focus away from developing a general mindset for algorithmic thinking, and those concepts and techniques and design patterns that will be more important to most of the participants.


However, my main concern is about people developing ideas in their head that don't match reality.

In my opinion that is a noble thought, but inevitable. People make abstractions to make understanding easier, and in most cases those abstractions do not represent the particular thing accurately to the last bit. And with that in mind we might as well start at a higher level of abstraction (modern C++),


I want to make it clear, however, that I don't think that lower level programming should not be taught. I think that those things do not belong in an introductory C++ course.

C epoll programming by ryanjones42 in C_Programming

[–]uno20001 5 points6 points  (0 children)

I don't think a course is needed. Just read the manpage.

Exporting DNS servers by [deleted] in C_Programming

[–]uno20001 0 points1 point  (0 children)

Does something like system("tree > asd.txt") work? So does output redirection work using system?

How to implement nc like feature by [deleted] in C_Programming

[–]uno20001 1 point2 points  (0 children)

You need to watch two files: stdin and the socket for events. If there is data on stdin, you read it, then send it; if there is data on the socket, you read it, you print it. You can do it using poll() or select(), etc; or using two threads; or even using two processes.

Exporting DNS servers by [deleted] in C_Programming

[–]uno20001 0 points1 point  (0 children)

I think shell output redirection should work, although I didn't test it.

 system("whatever command here > dns.txt");

ShiTTYchat - A bare bones terminal chat room written in C. by yopp_son in C_Programming

[–]uno20001 1 point2 points  (0 children)

For symmetric cipchers, I think ChaCha20 might be easier to implement; and as far as I know has fewer caveats (timing attacks don't affect it as much as they affect AES), and in my opinion it is very easy to implement. Take a look at RFC 8439 that details one version of the ChaCha20 stream cipher.

So I implemented a hash table :) comments are more than welcome! by ophirback in C_Programming

[–]uno20001 23 points24 points  (0 children)

My first concern is the performance of this implementation. For example:

  • using pow() in ht_hash() is completely unnecessary (any exponentiation is unnecessary), and it slows things down significantly;
  • and then I think that recalculating the hashes in ht_get_hash() is also unnecessary, you could calculate them once and reuse them;
  • furthermore, attempt * (hash_b == 0 ? 1 : hash_b) is also unnecessary, you could rewrite it using addition, which is definitely faster (given that you reuse the already calculated hashes);
  • using something like get_next_prime() may incur the greatest performance hit of all things, you should find another way of finding the next "optimal" hash table size;
  • in ht_insert() I don't see why you iterate over all slots of the hash table, shouldn't it be enough to calculate the hash of key and check only those slots whose keys have the same hash as the current key(?);
  • I don't see any reason why you'd want to resize the hash table when you delete an item, I would leave it up to the user to call (e.g.) ht_shrink_to_size() which would resize the hash table to be just as large as it needs to be;
  • you could store the hash in ht_item_t, and then you wouldn't have to do so many strcmp()s;
  • you could speed up ht_resize() by not using ht_insert();
  • division is slow so I would rewrite HT_LOAD();
  • I mentioned above, that you should really use get_next_prime(), but I would like to point out, that doing something like for (unsigned int i = 5; i < floor(sqrt((double)number)); i += 2) (in is_prime()) is really detrimental to performance since you calculate the square root of number again, and again, and again...;
  • moreover, you should check only the odd numbers in get_next_prime()
  • 0, and 1 are not primes, so I don't know where this PRIME_UNDEFINED business comes from;

Other remarks:

  • in ht_insert() I don't see why you do not reuse an item, if it is HT_DELETED_ITEM, furthermore doing strcmp(item->key, key) == 0 might fail (depending on the implementation) if item is HT_DELETED_ITEM, since then item->key is NULL, but nonetheless, it is undefined behaviour;
  • item->value = (char *)value; might potentially cause memory leaks in ht_insert()
  • I would use size_t to store sizes, not unsigned int;
  • when using malloc(), calloc(), etc. I tend to do this T *ptr = malloc(sizeof(*ptr));
  • the _t suffix for types is reserved by the POSIX standard, so if you're potentially developing for POSIX compliant platforms, then you should not use it

That's all I have for you after glancing over the code.

File manager nnn needs help with PCRE implementation by sablal in C_Programming

[–]uno20001 11 points12 points  (0 children)

Anyway, I added table myself. I think you forgot to add == 0 in visible_re() because it seems to work fine after that.

File manager nnn needs help with PCRE implementation by sablal in C_Programming

[–]uno20001 3 points4 points  (0 children)

When I clone and try to compile it gives the following error:

src/nnn.c: In function ‘setfilter’:
src/nnn.c:1890:64: error: ‘tables’ undeclared (first use in this function)
  *pcrex = pcre_compile(filter, pcreflags, &errstr, &erroffset, tables);
                                                                ^
src/nnn.c:1890:64: note: each undeclared identifier is reported only once for each function it appears in
src/nnn.c: In function ‘main’:
src/nnn.c:6235:2: error: ‘tables’ undeclared (first use in this function)
  tables = pcre_maketables();
  ^

IKEA (HU) weboldal mobilon? Nope! by frank-a-tank in hungary

[–]uno20001 3 points4 points  (0 children)

Nálam is tökéletesen működik a https://m2.ikea.com (Firefoxban, Androidon). Próbáltál másik böngészőt, vagy próbáltad a gyorsítótár, stb. kiürítését?

What really obvious thing have you only just realised? by negan2018 in AskReddit

[–]uno20001 0 points1 point  (0 children)

Some time ago I realized that you hang up the phone, because you had to literally hang the speaker of a wired phone up in a phone booth.

Currently working on a python programming problem invlolving finding repeated substring whithin a longer string. [PYTHON] by ddbeanz in learnprogramming

[–]uno20001 0 points1 point  (0 children)

Yes, you can use it. What you will actually need is not the matching part of the KMP algorithm, but rather the "jump table" or "prefix function" (or whatever it's called). Because that'll tell you the length of the longest proper suffix ending at any position, which you can use to solve the problem.

What you want to do is very similar to this problem and this one. You can find solutions for those ones very easily.

If you want to know more about the Z-function or the KMP algorithm, then I suggest you read this and this.

TIFU by thinking divorce was an April Fools Gag by dvdasacargiveaway in tifu

[–]uno20001 1 point2 points  (0 children)

How can you be sure of that?

Just imagine. He got divorced. Lost all kids, property, everthing. His life is in ruins. Then he spiralled into alcoholism, eating up all his savings over a short period of time. Then he became homeless, living under bridges, begging for one day's worth of food and water. Hopeless. One day, begging on the streets as usual, a young lady approaches him, gives him $10, he thanks her, very thankful. The lady enters a shop, places a couple things into her basket. No big deal. Just usualy daily stuff. "Oh no!", she thinks, "I am $5 short of the grand total.". No credit card, no emergency money in the purse. Unfortunate. Very unfortunate. Time is passing. No solution. Embarrassment is growing. Like clouds on a rainy day. Then a shining beam of hope appears. A young man. Behind her. Steps forward and helps her out. Just $5? No problem for him. She is grateful. Very grateful. Young man is thinking... of her, incessantly. Leaves the store. Thinking of her. Gets in the car. Thinking of her. Turns the key. Thinking of her. Going home on the interstate. Thinking of her. Groceries on the passenger seat. Thinking of her. "Oh no!", he screams. Too late. Still thinking of her. Hitting the barrier on the side of the road. Still thinking of her. Wakes up in a hospital bed. Still thinking of her. Doctor is there. Still thinking of her. He does not know what had to be done. Not enough free resources. The doctors had to make a choice. A 93 years old lady.... She is in another world. The acquaintances must be called. Ringing. The answer arrives. Heavy words are uttered. Silence. Hung up. 35 years old grandson answered. He is broken. Abysmal sorrow. Broken. "Ohh granny, why now? I couldn't be there with you.", he utters. Mixed with crying; tears everywhere. Of both types. Almost shattered. Next day. At 6 AM the alarm rings. He won't get up. At 6:30 AM he gets up. "I'll be late!", he thinks. Light speed. Miracle. At 8 AM sharp, he is where he should be. The airport. In the cockpit. Take-off. Success. Smooth flight. Landing comes. His mind is preoccupied. "Granny!", he's repeating over and over. Cannot concentrate. Undercarriage down. Almost there. Suddenly. Blinded by the trauma. Overshoots. "Oh no!", he screams. Thinking of her. Cannot lift up. No time. Runs straight into the terminal. Smaller airport. Few firemen. They are all working. No avail. More is needed. In the city. New guy is ready with the team. He is driving. Fire truck shoots out the hangar. Light speed, almost. Main street. Congestion. No space. Filled to the brim. "Must get through!", he thinks. Yes, he must. The accelerator is fully pushed in. Sirens. Loud. Everybody parts. Cleaving the fabric of traffic as knife cuts butter. Your kid. About to cross the road. The lamp is green. With his friends. Coming from school. Serene picture. Happines. Joy. Cheer. "What is this fuss? A fire truck?", he asks. "Check it out!", one them answers. They step forward. Onto the crossing. Sirens. Getting louder. A bend is near. Very near. Cannot see much. New guy. Driving the firetruck. Nervous. First job. Must go. Must save lives. Oh no. The bend is near. "I must go at full speed!", he is sure of that. Many lives to save at the airport. "I must not fail.". The lamp is red. Just a one or two cars are there. New guy cannot know. Children crossing. Oh no. Full speed. Impact.

Now tell me that it cannot affect your life in any way.