//C和C指针第六章Page115
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//第一题
char * find_char(char const * source, char const * chars){
if (source == NULL || chars == NULL)
return NULL;
char *s1, *s2;
for (s1 = source; *s1 != '\0'; s1++){
for (s2 = chars; *s2 != '\0'; s2++){
if (*s1 == *s2){
return s1;
}
}
}
}
//第二题
int del_substr(char *str, char const *substr){
if (str == NULL || substr == NULL)
return 0;
char * s1 = NULL, *s2 = NULL;
while (*str != '\0')
{
int nLenth = 0;
s1 = str;
s2 = substr;
while (*s1 != '\0' && *s2 != '\0' && *s1 == *s2){
nLenth++;
s1++;
s2++;
}
if (*s2 == '\0'){ //全匹配的标志
s2 = s1; //s2指针移动向s1的位置
s1 -= nLenth; //s1指针移动向匹配开始的位置。
while (
C和C指针--第6章习题
这篇博客介绍了C语言中关于指针的实践操作,包括使用指针查找字符串中特定字符的位置,删除子字符串以及反转字符串的方法。通过示例代码展示了如何实现这些功能,并在`main`函数中进行了测试。第二题的代码是博主自己编写的,可能存在不足,欢迎读者指导。
摘要由CSDN通过智能技术生成