hello;

I want to make the user write one character, not more than one and save it to char.

so how can I make the input limited to one char?

If I work with number only, how can I lock the letters input, making the user to input only numbers?

____________________________
Faizalw, C# and C++ prog learner
======================

I'm assuming you mean to use a non-standard input function, so it would be best to state your compler and OS.

If I work with number only, how can I lock the letters input, making the user to input only numbers?

You can do something like this

int number;
if(cin>>number){
//code
}
else{
//code
}

how can I make the input limited to one char?

Declare a character variable to hold the input.
Use >>, or its equivalent in C, to accept the input.
Flush the input buffer to remove anything else the user entered.

If I work with number only, how can I lock the letters input, making the user to input only numbers?

Short answer, you can't make the user input only numbers, or only char, or anything at all really. All you can do is validate that the input is the form, or can be tranformed into the form, you requested.

One approach to data validation is only accept input as a string and then transform the string into whatever other data type you want once you have validated it. The other scheme is to use an input stream and it's methods to do the validation. Neither scheme is straightforward, but it is a doable project once you have all your parameters in place.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.