C की ctype.h Functions
In this page:
#include <ctype.h>
isalpha(character);
isdigit(character);
toupper(character);
tolower(character);
Alphabets Check करना
isalpha() check करता है कि एक character A-Z या a-z की ranges में आता है या नहीं और अगर हाँ तो एक non-zero value return करता है, जो user input को एक number या symbol की बजाय एक name या word की तरह process करने से पहले यह validate करने का standard तरीका है कि इसमें सिर्फ letters हैं।
उदाहरण: Checking for Alphabets
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Include character-test functions (isdigit, toupper, ...)
#include <ctype.h>
// Program execution starts in main()
int main() {
// Print formatted text to the screen
printf("%d", isalpha('A'));
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Digits Check करना
isdigit() check करता है कि एक character decimal digits 0 से 9 में से एक है या नहीं, जो यह validate करने के लिए useful है कि एक number represent करने वाला input piece actually इसे atoi() जैसी किसी चीज़ से convert करने की कोशिश करने से पहले letters या punctuation नहीं रखता।
उदाहरण: Checking for Digits
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Include character-test functions (isdigit, toupper, ...)
#include <ctype.h>
// Program execution starts in main()
int main() {
// Print formatted text to the screen
printf("%d", isdigit('7'));
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Alphanumeric Check करना
isalnum() check करता है कि एक character एक letter है या एक digit, isalpha() और isdigit() जो individually check करते हैं उसे combine करते हुए, जो usernames या identifiers जैसी चीज़ें validate करते समय convenient है जिन्हें letters और numbers दोनों allow करने चाहिए लेकिन punctuation reject करना चाहिए।
उदाहरण: Checking for Alphanumeric
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Include character-test functions (isdigit, toupper, ...)
#include <ctype.h>
// Program execution starts in main()
int main() {
// Print formatted text to the screen
printf("%d %d", isalnum('A'), isalnum('!'));
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Case Conversions
tolower() एक uppercase letter को इसके lowercase equivalent में convert करता है और कोई भी character जो uppercase letter नहीं है उसे unchanged छोड़ देता है, जबकि toupper() उल्टा conversion करता है — दोनों C में case-insensitive string comparisons के standard building blocks हैं।
उदाहरण: Case Conversions
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Include character-test functions (isdigit, toupper, ...)
#include <ctype.h>
// Program execution starts in main()
int main() {
// Print formatted text to the screen
printf("%c %c", tolower('A'), toupper('b'));
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Whitespace Check करना
isspace() check करता है कि एक character recognized whitespace characters (space, tab, newline, carriage return, और कुछ और) में से एक है या नहीं, जो text parse करते समय leading और trailing blank characters skip या trim करने के लिए आमतौर पर इस्तेमाल होता है।
उदाहरण: Checking for Whitespace
// Include standard input/output (printf, scanf)
#include <stdio.h>
// Include character-test functions (isdigit, toupper, ...)
#include <ctype.h>
// Program execution starts in main()
int main() {
// Print formatted text to the screen
printf("%d %d", isspace(' '), isspace('a'));
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
isalphaयाtoupperइस्तेमाल करने से पहले#include <ctype.h>भूल जाना।- इन functions को एक negative
charvalue pass करना, जोunsigned charमें cast किए बिना undefined है। - यह उम्मीद करना कि
toupperएक पूरी string in place बदल देगा, जब यह एक character convert करता है।
Chapter Quiz — Complete all 20 topics to unlock
0/20 topics done
Complete these topics first:
- C typedef
- C Type Casting
- C Bit Fields
- C Variable Length Arrays
- C Command Line Arguments
- C Function Pointers
- C Callback Functions
- C Multidimensional Pointer
- C string.h Functions
- C stdlib.h Functions
- C math.h Functions
- C time.h Functions
- C ctype.h Functions
- C errno.h
- C assert.h
- C Error Handling
- C Debugging Techniques
- C Code Style & Best Practices
- C Common Mistakes
- C Interview Questions