How to determines whether a character is a letter or a digit in C++

1 Answer

0 votes
#include <iostream>

using namespace std;

int main()
{
	
	char ch = '9';
	if (isalpha(ch) || isdigit(ch))
		cout << "yes" << endl;
	else
		cout << "no" << endl;

	ch = 'a';
	if (isalpha(ch) || isdigit(ch))
		cout << "yes" << endl;
	else
		cout << "no" << endl;

	ch = '@';
	if (isalpha(ch) || isdigit(ch))
		cout << "yes" << endl;
	else
		cout << "no" << endl;

	return 0;
}


/*
run:

yes
yes
no

*/

 



answered Dec 6, 2016 by avibootz

Related questions

1 answer 166 views
1 answer 179 views
1 answer 171 views
1 answer 177 views
1 answer 161 views
...