Clibrary | <ctype.h>

前言

该库主要是处理字符函数;对字符进行判断,检查;

1、isalnum

int isalnum ( int c );

/*
* @func:检查字符是否为字母数字;
* @param c:要检查的字符,转换为int或EOF;
* return:若c确实是数字或字母 ,则该值不为0。否则为0;
*/

2、isalpha

int isalpha ( int c );

/*
* @func:检查字符是否为字母;
* @param c:要检查的字符,转换为int或EOF;
* return:若c确实是字母 ,则该值不为0。否则为0;
*/

3、isblank

int isblank ( int c );

/*
* @func:检查字符是否为空白字符【制表符 ( '\t' ) 和空格字符 ( ' ' )】;
* @param c:要检查的字符,转换为int或EOF;
* return:若c确实是空白字符 ,则该值不为0。否则为0;
*/

4、iscntrl

int iscntrl ( int c );

/*
* @func:检查字符是否为控制字符, 控制字符是0x00 (NUL) 和 0x1f (US) 以及 0x7f (DEL) 之间的字符;
* @param c:要检查的字符,转换为int或EOF;
* return:若c确实是控制字符 ,则该值不为0。否则为0;
*/

5、isdigit

int isdigit ( int c );

/*
* @func:检查字符是否为十进制数字;
* @param c:要检查的字符,转换为int或EOF;
* return:若c确实是十进制数字 ,则该值不为0。否则为0;
*/

6、isgraph

int isgraph( int c );

/*
* @func:检查字符是否为十进制数字;
* @param c:要检查的字符,转换为int或EOF;
* return:若c确实是字符的图形 ,则该值不为0。否则为0;
*/

7、islower

int islower( int c );

/*
* @func:检查字符是否为小写字母;
* @param c:要检查的字符,转换为int或EOF;
* return:若c确实是小写字母 ,则该值不为0。否则为0;
*/

8、isprint

int isprint( int c );

/*
* @func:检查字符是否为打印字符,大于0x1f,0x7f(DEL)除外;
* @param c:要检查的字符,转换为int或EOF;
* return:若c确实是打印字符 ,则该值不为0。否则为0;
*/

9、ispunct

int ispunct( int c );

/*
* @func:检查字符是否为标点;
* @param c:要检查的字符,转换为int或EOF;
* return:若c确实是标点 ,则该值不为0。否则为0;
*/

10、isspace

int isspace ( int c );

/*
* @func:检查字符是否为空格;
* @param c:要检查的字符,转换为int或EOF;
* return:若c确实是空格 ,则该值不为0。否则为0;
*/

空白字符

代码中ASCII按键
‘ ’0x20space
‘\t’0x09tab
‘\n’0x0a换行符
‘\v’0x0b垂直制表符
‘\F’0x0c
‘\r’0x0d回车

11、isupper

int isupper( int c );

/*
* @func:检查字符是否为大写字母;
* @param c:要检查的字符,转换为int或EOF;
* return:若c确实是大写字母 ,则该值不为0。否则为0;
*/

12、isxdigit

int isxdigit( int c );

/*
* @func:检查字符是否为十六进制数字;
* @param c:要检查的字符,转换为int或EOF;
* return:若c确实是十六进制数字,则该值不为0。否则为0;
*/

13、tolower

int tolower ( int c );

/*
* @func:将大写字母转为小写;
* @param c:要检查的字符,转换为int或EOF;
* return:等价于c的小写字母,否则为c。该值作为可以隐式转换为char的int值返回;
*/

14、toupper

int toupper ( int c );

/*
* @func:将小写字母转换为大写字母;
* @param c:要检查的字符,转换为int或EOF;
* return:等价于c的大写字母,否则为c。该值作为可以隐式转换为char的int值返回;
*/
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Sure, here's the modified code without using `<string.h>`, `<ctype.h>`, or `<stdbool.h>`: ```c #include <stdio.h> #include <stdlib.h> #define MAX_WORD_SIZE 80 #define ASCII_SIZE 128 void print_colored(char* text, char* color) { printf("\033[%sm%s\033[0m", color, text); } int strlen(char* str) { int len = 0; while (*str != '\0') { len++; str++; } return len; } int isalpha(int c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); } int isdigit(int c) { return c >= '0' && c <= '9'; } int isspace(int c) { return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' || c == '\v'; } int strcmp(char* str1, char* str2) { while (*str1 != '\0' && *str2 != '\0' && *str1 == *str2) { str1++; str2++; } return *str1 - *str2; } char* strstr(char* haystack, char* needle) { int needle_len = strlen(needle); if (needle_len == 0) { return haystack; } while (*haystack != '\0') { if (*haystack == *needle) { char* h = haystack; char* n = needle; while (*h != '\0' && *n != '\0' && *h == *n) { h++; n++; } if (*n == '\0') { return haystack; } } haystack++; } return NULL; } void decode(char* encoded_text, int n, char* decoded_text) { int i = 0; while (*encoded_text != '\0') { decoded_text[i] = ((*encoded_text - n) % ASCII_SIZE + ASCII_SIZE) % ASCII_SIZE; encoded_text++; i++; } decoded_text[i] = '\0'; } int main() { char word[MAX_WORD_SIZE + 1]; int n; char encoded_text[ASCII_SIZE]; fgets(word, MAX_WORD_SIZE + 1, stdin); scanf("%d", &n); getchar(); // read the newline character after n int i = 0; char c; while ((c = getchar()) != EOF && c != '\n') { encoded_text[i] = c; i++; } encoded_text[i] = '\0'; char decoded_text[ASCII_SIZE]; decode(encoded_text, n, decoded_text); if (strstr(decoded_text, word) != NULL) { print_colored("YES\n", "32"); // green color } else { print_colored("NO\n", "31"); // red color } return 0; } ``` I had to define some of the missing functions (`strlen()`, `isalpha()`, `isdigit()`, `isspace()`, `strcmp()`, and `strstr()`) using basic string manipulation techniques, since they are not available in the standard C library. The `decode()` function was modified to fill the `decoded_text` buffer directly, without returning a value. I hope this meets your requirements! Let me know if you have any questions.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jxiepc

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值