stdlib and colored output in C

All modern terminal emulators use ANSI escape codes to show colours and other things. Don’t bother with libraries, the code is really simple. More info is here. Example in C: #include <stdio.h> #define ANSI_COLOR_RED “\x1b[31m” #define ANSI_COLOR_GREEN “\x1b[32m” #define ANSI_COLOR_YELLOW “\x1b[33m” #define ANSI_COLOR_BLUE “\x1b[34m” #define ANSI_COLOR_MAGENTA “\x1b[35m” #define ANSI_COLOR_CYAN “\x1b[36m” #define ANSI_COLOR_RESET “\x1b[0m” int main … Read more

std::unique_ptr with an incomplete type won’t compile

Here are some examples of std::unique_ptr with incomplete types. The problem lies in destruction. If you use pimpl with unique_ptr, you need to declare a destructor: class foo { class impl; std::unique_ptr<impl> impl_; public: foo(); // You may need a def. constructor to be defined elsewhere ~foo(); // Implement (with {}, or with = default;) … Read more

C read file line by line

If your task is not to invent the line-by-line reading function, but just to read the file line-by-line, you may use a typical code snippet involving the getline() function (see the manual page here): #define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> int main(void) { FILE * fp; char * line = NULL; size_t len = 0; … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)