Oh, you mean there's a SPACE as the entire filename? Okay, then you can do:
/* version 1 */
if (filename[0] == ' ' && filename[1] == '\0') { ... do stuff here }
/* version 2 */
if (strcmp(filename," ")==0) { ... do stuff here ... }
filename[0] is the first character of the string. If the string is empty, the first character will be the terminator null byte.
C string-handling functions generally cannot read past a null byte. Your notation " ", `\0` is extremely non-standard, and seems to correspond to a string consisting of a space, followed by a null byte (which is usually not explicitly marked or required; it's the end of string, plain and simple). That string obviously has a length of one.
The C equality operator == does not compare strings in any meaningful way; you need to use a function such as strcmp. (I too thought this was shocking when I was learning C.) You can compare individual single characters (denoted by single quotes) one by one, which is what strcmp basically does in a loop over the strings it compares. Double quotes are used around strings (character arrays).
The C string tutorial which was already pointed out to you once probably explains all of this a lot better. Please read it.
Actually, his syntax with the comma serves to nullify the expression. Remember that a comma has lower precedence than just about anything else in C, and it creates an independent expression. C will use only the right-most part as the value for the entire expression. So
if (0==0, 0) { printf("false\n"); }
if (1==0, 1) { printf("true\n"); }
Helo thx for replying me.
I completely agree with you but problem is that
one of my function in file is appening " " for some other functionality
so that If enter filename as blank it will give me filename
as filename = " ",`\0`
Is the file name the empty string, or a string consisting of one space, or a string containing double quote, space, double quote, comma, backtick, backslash, zero, backtick?
All of these can be detected by strcmp
if ((stcmp(filename,""))==0) {
printf ("filename empty\n");
} else if ((strcmp(filename," "))==0) {
printf ("filename is a single space\n");
} else if ((stcmp(filename,"\" \",`\\0`"))==0) {
printf ("filename is literally \" \",`\\0`\n");
}
(Or is there even another space before the first double quote?)