Implementation of strcmp

Uhm.. way too complicated. Go for this one: int strCmp(const char* s1, const char* s2) { while(*s1 && (*s1 == *s2)) { s1++; s2++; } return *(const unsigned char*)s1 – *(const unsigned char*)s2; } It returns <0, 0 or >0 as expected You can’t do it without pointers. In C, indexing an array is using … Read more

Convert String^ in c# to CString in c++/CLI

Got My answer. Thanks for your support @Elliot Tereschuk. I have gone through some references like How to: Extend the Marshaling Library Overview of Marshaling in C++ For CString.Format() and include header files #include <msclr/marshal_windows.h> #include <msclr/marshal.h> using Library using namespace msclr::interop; And finally My source code is. String^ csPass = gcnew String(strPassword.GetBuffer()); array<Byte>^ Value … Read more

Why gets() is deprecated? [duplicate]

Can someone explains why the compiler shows like that…? Yes, because, the gets() function is dangerous, as it suffers from buffer overflow issue. Anyone should refrain from using that. Also, regarding the warning with -Wdeprecated-declarations, gets() is no longer a part of C standard [C11 onwards]. So, C libraries compilers are not bound to support … Read more

What are null-terminated strings?

What are null-terminating strings? In C, a “null-terminated string” is a tautology. A string is, by definition, a contiguous null-terminated sequence of characters (an array, or a part of an array). Other languages may address strings differently. I am only discussing C strings. How are they different from a non-null-terminated strings? There are no non-null-terminated … Read more

Why is strdup considered to be evil

Two reasons I can think of: It’s not strictly ANSI C, but rather POSIX. Consequently, some compilers (e.g. MSVC) discourage use (MSVC prefers _strdup), and technically the C standard could define its own strdup with different semantics since str is a reserved prefix. So, there are some potential portability concerns with its use. It hides … Read more