how to assign a null value to a string please tell me
how to assign a null value to a string
Page 1 of 13 Replies - 792 Views - Last Post: 19 November 2012 - 03:15 PM
Replies To: how to assign a null value to a string
#2
Re: how to assign a null value to a string
Posted 19 November 2012 - 11:40 AM
You need to show some code that shows what you have tried. Is this a C++ string or a C string?
Jim
Jim
#3
Re: how to assign a null value to a string
Posted 19 November 2012 - 11:41 AM
What does null value mean? The string should be empty? Also, which string? std::string or C-string?
#4
Re: how to assign a null value to a string
Posted 19 November 2012 - 03:15 PM
Null is usually used to simply terminate a string. Otherwise the standard string library functions have no idea where the end of the string ends.
i.e.
i.e.
char arr[6] {'a', 'b', 'c', 'd', 'e', 'f'}; //no null terminator printf("%s", arr); //printf will print all memory until a 0 is found in memory, very dangerous arr[5] = '\0'; //replace 'f' with null terminator printf("%s", arr); //prints abcde
This post has been edited by jjl: 19 November 2012 - 03:15 PM
Page 1 of 1