Say I have the following declared variable:
char mychararray[35];
and I want to set every character in the array to a blank space... How can I do that?
My instructor told me all I had to do was put
mychararray = "";
but that didn't work at all...
Am I using an outdated version of Visual Studio (2012), or is this just a bad initialization? If it is the latter, please explain how to make all the characters a blank space.
Thanks in advance!
You can initialize it the way your instructor suggested as you declare the array:
char mychararray[35] = "";
It will set the array to an empty string.
If you want to make it an empty string later, then you can just do
mychararray[0] = '\0';
If you want to make it an array consisting of 34 spaces (35th character being null terminator), then
memset(mychararray, ' ', 34);
mychararray[34] = '\0';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With