char a[100];
printf("enter name:");
fgets(a,strlen(a),stdin);
You are calling
strlen
on an unitialised array, so the result will be anything from zero to the largest integer value. A better way to do this is to use either a
#define
like this:
#define MAX_BUFFER 100
char a[MAX_BUFFER];
printf("enter name:");
fgets(a,MAX_BUFFER,stdin);
Or use the
sizeof
operator like this:
char a[100];
printf("enter name:");
fgets(a,sizeof(a),stdin);
[edit]
As Rick York suggest below, the size values in the call to
fgets
shoud be one less than the size of the buffer. Interestingly, the example in the Microsoft documentation fails to take that into account.
So in case 1 it should be:
fgets(a, MAX_BUFFER - 1, stdin);
and in case 2:
fgets(a, sizeof(a) - 1, stdin);
[/edit]