How to print in C

Very much a beginner to C, in fact this is my first tester program. I can’t actually figure out how to print this number out to the terminal. I am sure that in Java I could just replace the printf with System.out and it would have worked. I tried searching the answer earlier but if … Read more

How to convert an int to string in C?

EDIT: As pointed out in the comment, itoa() is not a standard, so better use sprintf() approach suggested in the rivaling answer! You can use itoa() function to convert your integer value to a string. Here is an example: If you want to output your structure into a file there is no need to convert … Read more

Using boolean values in C

From best to worse: Option 1 (C99 and newer) Option 2 Option 3 Option 4 Explanation Option 1 will work only if you use C99 (or newer) and it’s the “standard way” to do it. Choose this if possible. Options 2, 3 and 4 will have in practice the same identical behavior. #2 and #3 … Read more

uint8_t vs unsigned char

It documents your intent – you will be storing small numbers, rather than a character. Also it looks nicer if you’re using other typedefs such as uint16_t or int32_t.

What causes a segmentation fault (core dump) to occur in C?

Two things I see. First, you’re mixing chars with ints in the matrix array. Second, you’re printing the elements of matrix out to a file using the “%s” format. “%s” expects a null-terminated string where as you are passing chars and ints. This will cause the printf to try and access memory that is out-of-bounds, … Read more