How do you set an empty string...
char string[] = "";
or
char string[50] = "";
or are these both wrong?
How do you set an empty string...
char string[] = "";
or
char string[50] = "";
or are these both wrong?
Nothing can be empty it will have some value in it but if I get what you mean
would set all elements to \0, which is as close to empty as you can get.Code:char string[50] = '\0';
Last edited by C_Coder; 03-03-2002 at 03:50 PM.
All spelling mistakes, syntatical errors and stupid comments are intentional.
They will both work, but perform different purposes.
char CharArray[] = "Something"; // initialize the character string to what's between the "s plus the \0 character at the end.
so
char string[] = ""; // creates an array of one character which would be the \0 character.
char string[50] = ""; // creates an array of 50 characters with the initial string of \0.
You are right either way but it depends on what you want to do as to which one you should use.
A truly "empty" string would be
char *pString = NULL;
If a tree falls in the forest, and no one is around to see it, do the other trees make fun of it?