printf() formatting for hexadecimal

Why, when printing a number in hexadecimal as an 8 digit number with leading zeros, does %#08X not display the same result as 0x%08X? When I try to use the former, the 08 formatting flag is removed, and it doesn’t work with just 8.

munmap_chunk(): invalid pointer

In the function second(), the assignment word = “ab”; assigns a new pointer to word, overwriting the pointer obtained through malloc(). When you call free() on the pointer later on, the program crashes because you pass a pointer to free() that has not been obtained through malloc(). Assigning string literals does not have the effect of copying their content as you might have thought. To … Read more

Categories C Tags

What does “1e” mean?

I’ve seen some code online and I’m trying to work out what it is doing. In particular, I’ve never seen “1e” convention before.

Categories C Tags

What does “collect2: error: ld returned 1 exit status” mean?

The ld returned 1 exit status error is the consequence of previous errors. In your example there is an earlier error – undefined reference to ‘clrscr’ – and this is the real one. The exit status error just signals that the linking step in the build process encountered some errors. Normally exit status 0 means success, and exit status > 0 means errors. … Read more

Reading from file using read() function

Read Byte by Byte and check that each byte against ‘\n’ if it is not, then store it into bufferif it is ‘\n’ add ‘\0’ to buffer and then use atoi() You can read a single byte like this See read()

Why use bzero over memset?

I don’t see any reason to prefer bzero over memset. memset is a standard C function while bzero has never been a C standard function. The rationale is probably because you can achieve exactly the same functionality using memset function. Now regarding efficiency, compilers like gcc use builtin implementations for memset which switch to a particular implementation when a constant 0 is detected. Same for glibc when builtins are disabled.

segmentation fault : 11

This declaration: would occupy 8 * 1000 * 1000000 bytes on a typical x86 system. This is about 7.45 GB. Chances are your system is running out of memory when trying to execute your code, which results in a segmentation fault.