博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
编写一个函数,它从一个字符串中提取一个子字符串
阅读量:4030 次
发布时间:2019-05-24

本文共 595 字,大约阅读时间需要 1 分钟。

编写一个函数,它从一个字符串中提取一个子字符串。

函数原型如下:

int substr(char dst[], char src[],int start, int len){}

目标是:从 src 数组起始位置向后偏移 start个字符的位置开始,最多复制 len 个非NUL 字符到 dst数组。在复制完毕之后, dst 数组必须以 NUL字节结尾。函数的返回值是存储于 dst 数组中的字符串的长度。

注意指针使用前进行有效性判断(assert头文件为#include<stdio.h>)

代码如下:

#include
#include
#include
#include
void substr(char dst[], char src[], int start, int len){ assert(dst); assert(src); char *p = src + start; /*定义指针变量指向要提取字符串的地址 while(start) { src++;start--; } */ int n = strlen(p); printf("%d\n", n); /*求出要提取的字符串的长度 if(strlen(str)

本文出自 “” 博客,请务必保留此出处

转载地址:http://njlbi.baihongyu.com/

你可能感兴趣的文章
Selenium之前世今生
查看>>
Selenium-WebDriverApi接口详解
查看>>
Selenium-ActionChains Api接口详解
查看>>
Selenium-Switch与SelectApi接口详解
查看>>
Selenium-Css Selector使用方法
查看>>
Linux常用统计命令之wc
查看>>
测试必会之 Linux 三剑客之 sed
查看>>
Socket请求XML客户端程序
查看>>
Java中数字转大写货币(支持到千亿)
查看>>
Java.nio
查看>>
函数模版类模版和偏特化泛化的总结
查看>>
VMware Workstation Pro虚拟机不可用解决方法
查看>>
最简单的使用redis自带程序实现c程序远程访问redis服务
查看>>
redis学习总结-- 内部数据 字符串 链表 字典 跳跃表
查看>>
iOS 对象序列化与反序列化
查看>>
iOS 序列化与反序列化(runtime) 01
查看>>
iOS AFN 3.0版本前后区别 01
查看>>
iOS ASI和AFN有什么区别
查看>>
iOS QQ侧滑菜单(高仿)
查看>>
iOS 扫一扫功能开发
查看>>