String
-
If I assign a string to a variable. char* t = "Hello World!"; Doesn't this string get a fixed array with a null terminator at the end?
-
If I assign a string to a variable. char* t = "Hello World!"; Doesn't this string get a fixed array with a null terminator at the end?
-
If I assign a string to a variable. char* t = "Hello World!"; Doesn't this string get a fixed array with a null terminator at the end?
No. It assigns a pointer to a fixed null-terinated string, there is a slight difference between arrays and pointers. A writable block of memory is not allocated and you should get a compiler warning because of the unsafe conversion... change the code to: const char* t = "Hello World!"; Hope this helps :)
-
Yes. Take a look at it in the debugger if you are not sure.
Just say 'NO' to evaluated arguments for diadic functions! Ash
wcscat_s keeps throwing an error that the string isn't null terminated! :S
-
wcscat_s keeps throwing an error that the string isn't null terminated! :S
Are you sure it doesn't throw an exception, because the memory provided in
strDestination
argument is read-only? -
If I assign a string to a variable. char* t = "Hello World!"; Doesn't this string get a fixed array with a null terminator at the end?
every literal string gets a NULL appended automatically by the compiler. However there are 8-bit and 16-bit characters and strings, and you can't just mix them. If you use wcscat_s, you want wide char strings, the example in MSDN is:
wchar_t wszStr[] = L"1a1g";
:)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
wcscat_s keeps throwing an error that the string isn't null terminated! :S
Fareed Rizkalla wrote:
wcscat_s keeps throwing an error that the string isn't null terminated!
Yes, I'm not surprised since you are sending it a
char*
(i.e. ASCII string) butwcscat_s()
expects Unicode.Just say 'NO' to evaluated arguments for diadic functions! Ash
-
No. It assigns a pointer to a fixed null-terinated string, there is a slight difference between arrays and pointers. A writable block of memory is not allocated and you should get a compiler warning because of the unsafe conversion... change the code to: const char* t = "Hello World!"; Hope this helps :)
Moak wrote:
a pointer to a fixed null-terinated string,
Which is simply an array of characters.
Moak wrote:
there is a slight difference between arrays and pointers.
I would say there is a huge difference.
Just say 'NO' to evaluated arguments for diadic functions! Ash