You can check the null by checking the input using the strcmp function.

Code:
#include<stdio.h>
#include<string.h>
main()
{
        char str[100];
        printf("Enter the value : ");
        gets(str);
        if(strcmp(str,"\0")==0)
        {
                printf("Null entered \n");
        }
        else
        {
        printf("%s",str);
        }

}
Try to avoid gets,instead you can use fgets .

The same requirement using fgets is,

Code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
main()
{
        char str[100];
        printf("Enter the value : ");
        if(fgets (str,sizeof(str),stdin)==NULL)
        {
                printf("fgets : read error \n");
                exit(1);
        }
        if(strcmp(str,"\n")==0) // Because fgets store the '\n'.
        {
                printf("Null entered \n");
        }
        else
        {
        printf("%s",str);
        }

}
cheers

Last edited by karthigayan; 15Mar2010 at 10:35..
askmewhy25 like this