Atlas - ctype.c

Home / lab / trail / c / header Lines: 7 | Size: 2078 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* SPDX-License-Identifier: GPL-3.0 2 * The Language Trail 3 * 4 * ctype.c 5 * 6 * Exploration of the <ctype> standard header. This header is pretty self 7 * explanatory, but useful. 8 * 9 * https://en.cppreference.com/w/c/header/ctype.html 10 * 11 * COPYRIGHT NOTICE 12 * Copyright (C) 2025 0x4248 and contributors 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the license is not changed. 15 * 16 * This software is free and open source. Licensed under the GNU general 17 * public license version 3.0 as published by the Free Software Foundation. 18*/ 19 20#include <ctype.h> 21#include <stdio.h> 22 23// ########## CHECKLIST ########## 24// isalnum [TODO] 25// isalpha [X] 26// islower [X] 27// isupper [TODO] 28// isdigit [TODO] 29// isxdigit [TODO] 30// iscntrl [TODO] 31// isgraph [TODO] 32// isspace [TODO] 33// isblank [TODO] 34// isprint [TODO] 35// ispunct [TODO] 36// tolower [TODO] 37// toupper [TODO] 38 39/** isLower(chr) 40 * checks if a char is "abcdefghijklmnopqrstuvwxyz" 41 * 42 * Return: 0 on lowercase, non zero on uppercase (int: 512) 43 */ 44void test_isLower(){ 45 char str[12] = "aBcDEfg123!#"; 46 for (int i = 0; i < sizeof(str); i++) { 47 if(islower(str[i])){ 48 printf("%c\tis lowercase\n",str[i]); 49 } else { 50 /* This is not always true, see in the testing you can see the 51 * numbers printed with the uppercase, but yet again its only 52 * checking for "abcdefghijklmnopqrstuvwxyz" 53 */ 54 printf("%c\tis UPPERCASE\n",str[i]); 55 } 56 57 } 58} 59 60/** isalnum(chr) 61 * checks if a char is a number or a letter in latin. 62 * 63 * Return: 0 on alphanumeric, non zero on non alphanumeric 64 */ 65void test_isalnum(){ 66 char str[12] = "aBcDEfg123!#"; 67 for (int i = 0; i < sizeof(str); i++) { 68 if(isalnum(str[i])){ 69 printf("%c\tTRUE\n",str[i]); 70 } else { 71 printf("%c\tFALSE\n",str[i]); 72 } 73 74 } 75} 76 77 78 79int main(void){ 80 printf("---[isLower]---\n"); 81 test_isLower(); 82 printf("---[isalnum]---\n"); 83 test_isalnum(); 84 return 0; 85} 86
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.