How can I detect a null string?
--if a user type nothing but simply a "Enter" key then a message is shown
How can I detect a null string?
--if a user type nothing but simply a "Enter" key then a message is shown
How are you reading the input, what is the function you are using to read the input??? The basica idea would be to count the number of characters read, that should give you an idea of how many characters the user entered.
You can scan for null string using scanf("\n")How can I detect a null string?
However, if you wish to match specific enter key, you might want to consider using if statement. You have to declare a variable if you use if statement to match though
>--if a user type nothing but simply a "Enter" key then a message is shown
Since you should be using fgets for string data , simply test to see if fgets returns NULL for EOF. To check if the user simply typed return check the first character of the array for '\n', otherwise they gave you more than nothing.
-PreludeCode:#include <stdio.h> int main ( void ) { char a[BUFSIZ]; if ( fgets ( a, sizeof a, stdin ) == NULL ) puts ( "Oops, no input read" ); else if ( a[0] == '\n' ) puts ( "Don't just hit enter, type something" ); else printf ( "You typed \"%s\"\n", a ); return 0; }
My best code is written with the delete key.
Depends on what you mean by a NULL string:
Code://The pointer is NULL, no string if(String == NULL)Code://The string is empty if(strcmp(String, "") == 0)Code://If the string begins with a NULL terminator, basically the same as #2. if(String[0] == '\0')Code://If the string contains the letters NULL if(strcmp(String, "NULL") == 0)
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Thank you all!