Hot answers tagged

30 votes

Perl CGI script to serve a PDF file

I will go through your code line by line and give feedback. We will skip the general advice on don't use CGI as it's actually suited for what you are trying to do here. I wrote this answer in two ...
  • 993
27 votes
Accepted

Please Save My Name

You manage to do the right thing, but the way that you do it is a bit... what shall we say...? twisted? backwards? non-optimal! Your approach: Get list of all files in directory Loop over a range ...
25 votes
Accepted

Explicit song lyrics checker

I recommend practicing Python 3 rather than Python 2 these days. According to PEP 8, isClean() should be is_clean(). One or ...
23 votes
Accepted

Wanted a cat. Got lolcat

C would have allowed you to just ignore errors and pretend everything was good. A naïve cat would be very short, but rather unreliable also. A well‐written ...
22 votes
Accepted

92 Spoons AI, sort of an AI in C++

There's a lot to say here, so let's not waste any time and jump right into it: You said that you didn't want to hear the using namespace std;-drill, but ...
  • 5,220
22 votes
Accepted

Can I slim this UTF8-encoding program?

Efficient file I/O By default, files opened with fopen() are buffered, meaning that not every call to fread() or ...
  • 35.8k
22 votes

Can I slim this UTF8-encoding program?

log is already declared in <math.h>. You don't need to declare it yourself. In fact, it could be harmful. As stated in ...
  • 54.2k
21 votes
Accepted

Can I buff up your file?

1. Bugs If the open succeeds but the lseek fails (as it might if the file is a named pipe), the function omits to close the ...
  • 49.3k
21 votes

Explicit song lyrics checker

Splitting line into words using words = line.split(" ") will only split the line on space ...
  • 32.2k
20 votes
Accepted

Convert Bitmap Font to Texture Atlas

Turning my comment into an answer by request. You should be able to do what you want by simply using the functionality already built into LibGDX. Caveat: I have not tried this, I just know that the ...
  • 16.4k
17 votes
Accepted

Writing computer generated music to a .wav file in C

Endianness Your program works on little endian machines only. If you care for it to work on any machine, you would need to fix up all of the fwrite() calls to ...
  • 28.4k
16 votes

92 Spoons AI, sort of an AI in C++

Here are some things that may help you improve your code. Don't abuse using namespace std I know you said you don't want to hear this, but your code is unusable ...
  • 64.6k
16 votes

Explicit song lyrics checker

Some suggestions: Using argparse to parse arguments is preferable to any kind of interactive input, because it means that it's much easier to automate and ...
  • 8,747
15 votes

Reversing the lines of a file

The posted code does the following: Read all lines, just for counting Create an array with the right size Read all lines again, this time for storing Print all lines in reverse order It's wasteful ...
  • 110k
15 votes
Accepted

Writing a large file of numbers

Few things. This number: unsigned long max = std::numeric_limits<unsigned long>::max(); Is 18446744073709551615 If ...
  • 92.1k
15 votes

Writing computer generated music to a .wav file in C

fopen should have a b in the second parameter. This primarily prevents windows from replacing any ...
15 votes

Markov chains to generate text

Functions Split the code into functions, also split the generation and the presentation. Your algorithm has some clear distinct tasks, so split along these lines: read input assemble chain construct ...
15 votes

Program that finds the longest word not containing one of the disallowed characters

I see a number of things that may help you improve your program. Fix the bug There is a subtle bug in the original implementation. It contains these lines: ...
  • 64.6k
15 votes
Accepted

Average spam confidence

Not duplicating any of @Peilonrayz's code review points ... Stop reading entire files into memory when you can process the file line by line in one pass, and stop creating huge lists in memory which ...
  • 32.2k
15 votes
Accepted

A simple error messaging and logging system via macro(s) in C++

You’ve already noted that this could be done better without macros, so I won’t belabour the point. I will note, though, that your goal—“to refresh [your] skills at writing good solid macros”—makes ...
  • 9,036
13 votes
Accepted

Showing the contents of a file

Magic numbers 20 and 19? Instead of this: char fileName[20]; // Get the filename from the user: int fileNameLength = read(0,fileName,19); Define ...
  • 110k
13 votes

Convert Bitmap Font to Texture Atlas

The purpose of constructors The purpose of constructors is to create objects. The constructor of FntToAtlasGenerator is something else entirely: it takes some ...
  • 110k
12 votes

Writing computer generated music to a .wav file in C

It actually doesn't look too bad. Some minor nitpicks You shouldn't cast the return value of malloc. fByteRate and ...
  • 20.1k
12 votes

Reading a DHT11 to a file

Here is a list of things I would improve: define constants in upper-case (PEP8 reference) put the main program logic into the if __name__ == '__main__': to avoid ...
  • 17.1k
12 votes

92 Spoons AI, sort of an AI in C++

Header files You have a lot of implementation code in that header file (files.h). Header files should only contain the function or class headers, the implementation should go into an extra cpp file. ...
12 votes

Comparing two large binary files in C

fread (tmp1, sizeof *tmp1, readsz, fp1); fread (tmp2, sizeof *tmp2, readsz, fp2); count += 16; if(memcmp(tmp1, tmp2, readsz)){ … } You are discarding the ...
12 votes

Basic C copy file implementation

You test the return value of fwrite, which is good. However, fread may fail as well. Since ...
  • 54.2k
12 votes

Average spam confidence

I think ask_file_name looks fine without using pathlib. The difference between the two comes down to LBYL vs EAFP. For the most ...
  • 41.7k
12 votes

Read file into vector<byte>

Nice: using bytes = std::vector<std::byte>; I would call it Bytes to make it clear it is a type rather than an object. ...
  • 92.1k
11 votes
Accepted

Text Analyzer - Properly implementing Java coding style

Single responsibility principle The main method does most of the job. It would be better to split that up to smaller methods, in a way that each method has a ...
  • 110k

Only top scored, non community-wiki answers of a minimum length are eligible