EDIT@ I'll just use a string as I can't seem to find a way to solve this with a character
I have the following:
char character;
int valid = 1;
do {
if( valid == 0 ) {
printf("ERROR");
}
valid = 1; // Validates it again if the do while loop activates
character = inputCharacter("Insert the character: ");
system("clear");
if( certainCondition ) {
valid = 0;
}
} while( valid != 1 );
inputCharacter being:
char inputCharacter(char* message) { // Inputs a character
char character;
printf("%s", message);
scanf(" %c", &character);
return character;
}
This function will accept a character and if it is equal to an another character I've typed before it will ask for a new character.
What I wanted to know is:
Is it possible to check if the character input has more than one character, and if so, ask for a new character input while giving an "ERROR: One character only"?
Example:
First character: e
Insert the character: e | ERROR
Insert the character: easd | ERROR: Please insert one character only
Insert the character: wflek | ERROR: Please insert one character only
Insert the character: a | accepts
Is this possible without the use of a string?
(It is fine if I can't give out the error while not allowing more than one character but it would be cool if I was able to)