How to do scanf for single char in C

The %c conversion specifier won’t automatically skip any leading whitespace, so if there’s a stray newline in the input stream (from a previous entry, for example) the scanf call will consume it immediately. One way around the problem is to put a blank space before the conversion specifier in the format string: The blank in the format string tells scanf to … Read more

How to initialize array to 0 in C?

Global variables and static variables are automatically initialized to zero. If you have simply at global scope it will be all zeros at runtime. But actually there is a shorthand syntax if you had a local array. If an array is partially initialized, elements that are not initialized receive the value 0 of the appropriate type. You … Read more

waitpid, wnohang, wuntraced. How do I use these

If you pass -1 and WNOHANG, waitpid() will check if any zombie-children exist. If yes, one of them is reaped and its exit status returned. If not, either 0 is returned (if unterminated children exist) or -1 is returned (if not) and ERRNO is set to ECHILD (No child processes). This is useful if you want to find out if any of your children recently died without having … Read more