stdio.h not standard in C++?

stdio.h is standard, but deprecated. Always prefer cstdio in C++. [n3290: C.3.1/1]: For compatibility with the Standard C library, the C++ standard library provides the 18 C headers (D.5), but their use is deprecated in C++. [n3290: D.5/3]: [ Example: The header <cstdlib> assuredly provides its declarations and definitions within the namespace std. It may … Read more

GCC fatal error: stdio.h: No such file or directory

macOS I had this problem too (encountered through Macports compilers). Previous versions of Xcode would let you install command line tools through xcode/Preferences, but xcode5 doesn’t give a command line tools option in the GUI, that so I assumed it was automatically included now. Try running this command: xcode-select –install If you see an error … Read more

Is there a Windows equivalent to fdopen for HANDLEs?

Unfortunately, HANDLEs are completely different beasts from FILE*s and file descriptors. The CRT ultimately handles files in terms of HANDLEs and associates those HANDLEs to a file descriptor. Those file descriptors in turn backs the structure pointer by FILE*. Fortunately, there is a section on this MSDN page that describes functions that “provide a way … Read more

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

Reading a line using scanf() not good?

char * fgets ( char * str, int num, FILE * stream ); is safe to use because it avoid buffer overflow problem, it scans only num-1 number of char. Reads characters from stream and stores them as a C string into str until (num-1) characters have been read or either a newline or the … Read more

Code for printf function in C [duplicate]

Here’s the GNU version of printf… you can see it passing in stdout to vfprintf: __printf (const char *format, …) { va_list arg; int done; va_start (arg, format); done = vfprintf (stdout, format, arg); va_end (arg); return done; } See here. Here’s a link to vfprintf… all the formatting ‘magic’ happens here. The only thing … Read more

tech