The content on this website, including videos and code examples, is for educational purposes only. All demonstrations and designs are fictional and created to illustrate coding techniques. Any resemblance to existing websites or brands is purely coincidental.
The creators and administrators of this website do not claim ownership or affiliation with any existing websites or companies. Users are encouraged to use the information responsibly for learning purposes. Liability for any misuse of the content provided is not accepted.
Reading a character: We use the analogous function "getchar()".
To check the input character type:
1) isalpha to check for alphabet character.
2) isalnum to check for the alphanumeric character.
3) isdigit to check for numeric digit.
4) islower to check for the lowercase letter.
5) isupper to check for the uppercase letter.
Writing a character: We use the analogous function "putchar()".
Rules for scanf:
1) Each variable to be read must have a filed specification.
2) For each field specification, there must be a variable address of the proper type.
3) Any non-whitespace character used in the format string must have a matching character in the user input.
4) The scanf reads until a whitespace character found.
5) The scanf reads until the maximum number of character have been read.
6) The scanf reads until an error is detected.
7) The scanf reads until the end of file is reached.
Program to read a character:
reading_a_character.c
#include <stdio.h>
void main() {
char subs;
printf("Have you subscribed to customizedDev?\n");
subs = getchar();
if(subs == 'Y' || subs == 'N') {
printf("keep supporting, thank you");
} else {
printf("please subscribe to channel for programming and customization videos");
}
}
Program to check for the type of a character:
checking_for_type_a_character.c
#include <stdio.h>
#include <ctype.h>
void main() {
char test_var;
printf("Enter a character: ");
test_var = getchar();
if (isalpha(test_var) > 0) {
printf("\nCharacter is alphabet.");
} else if (isdigit(test_var) > 0) {
printf("\nCharacter is numeric digit.");
} else {
printf("\nCharacter is not alphanumeric.");
}
}
Program to convert the type of a character:
changing_type_of_character.c
#include <stdio.h>
#include <ctype.h>
void main() {
char char_to_be_converted;
printf("Enter an alphabet: ");
char_to_be_converted = getchar();
printf("\nInverted Character: ");
if (islower(char_to_be_converted) > 0) {
putchar(toupper(char_to_be_converted));
} else {
putchar(tolower(char_to_be_converted));
}
}
Program to read a string:
reading_string.c
#include <stdio.h>
void main() {
char string[10];
printf("Enter a string: ");
scanf("%d", &string);
printf("\nYou have entered: %s", string);
}