diff --git a/2207/C语言同步练习源码/5.指针-3.c b/2207/C语言同步练习源码/5.指针-3.c new file mode 100644 index 0000000..2c1e7f3 --- /dev/null +++ b/2207/C语言同步练习源码/5.指针-3.c @@ -0,0 +1,19 @@ +#include + +int main(){ + char str[] = "AbcDEfg"; + char *p = str; + + while(*p != '\0'){ + if(*p >= 'a' && *p <= 'z'){ + *p -= 32; + }else{ + *p += 32; + } + p++; + } + puts(str); + + return 0; +} + diff --git a/2207/C语言同步练习答案.md b/2207/C语言同步练习答案.md index 15a4f74..b3b7d24 100644 --- a/2207/C语言同步练习答案.md +++ b/2207/C语言同步练习答案.md @@ -808,6 +808,28 @@ int main(){ ![image-20250227231232971](https://yp.smallkun.cn/markdown/image-20250227231232971.png!compress) +```c +#include + +int main(){ + char str[] = "AbcDEfg"; + char *p = str; + + while(*p != '\0'){ + if(*p >= 'a' && *p <= 'z'){ + *p -= 32; + }else{ + *p += 32; + } + p++; + } + puts(str); + + return 0; +} + +``` + ### 指针-4