fopen("/img/logo.png","x");
It will not create the img directory in any case. If the directory does not exist, then it will always throw this warning.
Warning: fopen(/img/logo.png): failed to open stream: No such file or directory
fopen("logo.png","x");
If logo.png does not already exist, then it will create it without any warning.
If logo.png already exists, then it will always throw this warning.
Warning: fopen(logo.png): failed to open stream: No such file or directory
fopen("","x") is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call. Now let me help you understand why it happens.
In POSIX, The O_CREAT flag causes a file to be created if it doesn't
already exist. If you include the O_CREAT flag, you must also pass a third argument to open to designate the permissions. If you want to avoid writing over an existing file, use the combination O_CREAT | O_EXCL. This combination returns an error if the file already exists.
C program using POSIX
#include <fcntl.h>
#include <sys/stat.h>
int open(const char *path, int oflag, ...);
Conclusion:
So we will use the "x" mode only when we want to avoid writing over an existing file.