C char array initialization

This is not how you initialize an array, but for: The first declaration: char buf[10] = “”; is equivalent to char buf[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; The second declaration: char buf[10] = ” “; is equivalent to char buf[10] = {‘ ‘, 0, 0, 0, 0, 0, 0, … Read more

Allocating char array using malloc

Yes, it’s a matter of style, because you’d expect sizeof(char) to always be one. On the other hand, it’s very much an idiom to use sizeof(foo) when doing a malloc, and most importantly it makes the code self documenting. Also better for maintenance, perhaps. If you were switching from char to wchar, you’d switch to … Read more

casting int to char using C++ style casting

You should use static_cast<char>(i) to cast the integer i to char. reinterpret_cast should almost never be used, unless you want to cast one type into a fundamentally different type. Also reinterpret_cast is machine dependent so safely using it requires complete understanding of the types as well as how the compiler implements the cast. For more information about C++ casting see: When should static_cast, … Read more

Does C have a string type?

C does not and never has had a native string type. By convention, the language uses arrays of char terminated with a null char, i.e., with ‘\0′. Functions and macros in the language’s standard libraries provide support for the null-terminated character arrays, e.g., strlen iterates over an array of char until it encounters a ‘\0’ … Read more

How to empty a char array?

using in general if the array is in scope, or if you only have the pointer value, and nMembers is the number of elements in the array. EDIT Of course, now the requirement has changed from the generic task of clearing an array to purely resetting a string, memset is overkill and just zeroing the first element … Read more

Unclosed Character Literal error

In Java, single quotes can only take one character, with escape if necessary. You need to use full quotation marks as follows for strings: You also used which I assume should be Note: When making char values (you’ll likely use them later) you need single quotes. For example:

Char Comparison in C

I’m trying to compare two chars to see if one is greater than the other. To see if they were equal, I used strcmp. Is there anything similar to strcmp that I can use?

Removing “NUL” characters

This might help, I used to fi my files like this: http://security102.blogspot.ru/2010/04/findreplace-of-nul-objects-in-notepad.html Basically you need to replace \x00 characters with regular expressions

tech