Description:

In this program you can check wether the user`s input is a valid name or not it will check the input character by character and if the whole input contains only alphabets and spaces it will print the name or you can use it as your requirements.

Code

# include”stdio.h”
# include”conio.h”
# include”strings.h”

int main(void)
{
char name[40]; //for name
char check[53],val=65; //for checking elements val=65 coz a=65
int num1=0,num2=0;
for(int k2=0;k2<=51;k2++,val++)
{
if(k2==26) //coz we have to use small letters as well
{
val+=6;
}
check[k2]=val;
printf(“%c”,check[k2]);
}
check[52]=32; //for adding space
printf(“Please Enter a string :\t”); //entering name
gets(name);
num1=strlen(name);
for(int k=0;k<num1;k++) // for checking
{
for(int k1=0;k1<=52;k1++)
{
if(name[k]==check[k1])
{
num2++;
}
}
} //checking ended
printf(“%s”,name);
if(num1==num2)
{
printf(name);
}
}

Advertisements