用指针实现库函数strncpy strncmp strncat
来源:互联网 发布:子宫肌瘤微创手术知乎 编辑:程序博客网 时间:2024/05/18 02:19
#include <stdio.h> #define MAX 1000 void strncat(char *s,char *t,int n); int strncmp(char *s,char *t,int n); void strncpy(char *s,char*t,int n); int len(char *s); int main(void) { char s[MAX],t[MAX]; int n; printf("Please enter your string s : "); gets(s); printf("Please enter your string t : "); gets(t); printf("Please enter your number n : "); scanf("%d",&n); strncmp(s,t,n); // strncpy(s,t,n); // strncat(s,t,n); printf("%d",strncmp(s,t,n)); return 0; } int len(char *s) { int i; for(i=0;*s!='\0';s++,i++) ; return i; } void strncat(char*s,char*t,int n) { int i; if(len(t)<n) printf("The string t isn't long enough, we will paste the whole sting.\n"); for(;*s!='\0';s++); //移动到s的末端 for(i=0;i<n;i++ ,*s++=*t++) ; *s='\0'; //给s封尾 } void strncpy(char *s,char *t,int n) { int i; if(len(s)<n) printf("The string s isn't long enough, Please enter your number n again.\n"); if(len(t)<n) printf("The string t isn't long enough, we will copy the whole sting.\n"); for(i=0;i<n;*s++=*t++,i++) ; } int strncmp(char *s,char *t,int n) //比较前s与t的前n个元素,返回第一个不相等字符处的字符的差值 { int i; if(len(s)<n) printf("The string s isn't long enough, Please enter your number n again.\n"); if(len(t)<n) printf("The string t isn't long enough, Please enter your number n again.\n"); for(i=0; i<n, *s==*t; s++,t++,i++); return *s-*t; }
0 0
- 用指针实现库函数strncpy strncmp strncat
- strncmp、strncpy、strncat、strlen库函数的实现
- 模拟实现C库函数strncpy、strncat、strncmp
- 模拟实现C库函数:strncpy、strncat和strncmp
- 模拟实现strncpy,strncat,strncmp
- 模拟实现strncpy,strncat,strncmp
- 模拟实现strncpy,strncat,strncmp
- 模拟实现strncpy,strncat,strncmp
- 《c程序设计语言》读书笔记-5.5-指针实现strncpy,strncat,strncmp
- 【C语言】 实现strncpy,strncat,strncmp
- strncmp和strncat库函数的实现。
- C和指针之字符串之strncpy、strncat、strncmp
- 从0开始<十三>:getint()函数(类似于scanf函数)以及库函数strncpy、strncat及strncmp函数的实现
- 模拟实现strncpy ,模拟实现strncat ,模拟实现strncmp
- 模拟实现C语言strncpy.strncat.strncmp函数
- 【C语言】模拟实现strncpy、strncat、strncmp函数
- 模拟实现strcpy,strncpy,strcat,strncat,strcmp,strncmp,memcpy,memmove
- strncmp, strncat, strncpy函数的定义与实现
- 画圆形背景头像
- 垂直互联网的思考
- HDU 5787 K-wolf Number (数位DP)
- JSON 教程
- Javascript实现继承的6种方式
- 用指针实现库函数strncpy strncmp strncat
- hdu 2089(数位DP)
- HDU 2817 A sequence of numbers (数学+快速幂)
- tensorflow example
- CodeForces703B Mishka and trip 数学
- Centos6.5 双网卡配置一个上外网一个接局域网
- 基于jquery的轮播插件操作
- ThreadPoolTaskExecutor线程池
- C#实体类中在数据类型后面添加问号是什么意思