写自己的strcat函数------→mycat

 #include <stdio.h>
#include <string.h>
#define N 5 char *mycat(char *s1, char *s2)
{
//数组型
/* int i = 0;
while(s1[i] != '\0') {
i++;
}
int j = 0;
while(s2[j] != '\0') {
s1[i] = s2[j];
i++;
j++;
}
s1[i] = '\0'; return s1; */
//指针型
char *p = s1; //定义字符型指针p指向s1
while(*s1 != '\0') { //让s1指向'\0'
s1++;
}
while(*s2 != '\0') { //让s2连在s1后
*s1 = *s2;
s1++;
s2++;
}
*s1 = '\0'; //让s1以'\0'结尾 return p; } int main()
{
char s1[N];
char s2[N];
fgets(s1, N, stdin);
if(s1[strlen(s1) - ] == '\n') { // 去掉换行符
s1[strlen(s1) - ] = '\0';
}
fflush(stdin); //因为上面使用了fgets,这里得清空缓冲区(具体请看gets和fgets函数的区别
fgets(s2, N, stdin);
if(s2[strlen(s2) - ] == '\n') { // 去掉换行符
s2[strlen(s2) - ] = '\0';
}
printf("%s", mycat(s1, s2));
// printf("%s\n%s", s1, s2); return ;

编写一个程序实现strcat函数的功能的更多相关文章

  1. 编写一个程序实现strcmp函数的功能

    写自己的strcat函数------→mycmp #include <stdio.h> #include <string.h> #define N 5 int mycmp(ch ...

  2. 编写一个程序实现strcpy函数的功能

    #include <stdio.h> #include <string.h> #define N 5 char *mycpy(char *s1, char *s2) { //数 ...

  3. 编写一个程序实现strlen函数的功能

    写自己的 strlen 函数-----→ mystrlen #include <stdio.h> #include <string.h> #define N 100 int m ...

  4. python练习:编写一个程序,要求用户输入10个整数,然后输出其中最大的奇数,如果用户没有输入奇数,则输出一个消息进行说明。

    python练习:编写一个程序,要求用户输入10个整数,然后输出其中最大的奇数,如果用户没有输入奇数,则输出一个消息进行说明. 重难点:通过input函数输入的行消息为字符串格式,必须转换为整型,否则 ...

  5. python练习:编写一个程序,要求用户输入一个整数,然后输出两个整数root和pwr,满足0<pwr<6,并且root**pwr等于用户输入的整数。如果不存在这样一对整数,则输入一条消息进行说明。

    python练习:编写一个程序,要求用户输入一个整数,然后输出两个整数root和pwr,满足0<pwr<6,并且root**pwr等于用户输入的整数.如果不存在这样一对整数,则输入一条消息 ...

  6. 编写一个程序,求s=1+(1+2)+(1+2+3)+…+(1+2+3+…+n)的值

    编写一个程序,求s=1+(1+2)+(1+2+3)+…+(1+2+3+…+n)的值 1 #import <Foundation/Foundation.h>  2   3 int main( ...

  7. 面试题之java 编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串。 要求不能出现截半的情况

    题目:10. 编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串. 但是要保证汉字不被截半个,如"我ABC"4,应该截为"我AB",输 ...

  8. 已知一个正整数m,编写一个程序求m的反序数(待消化)

    import java.util.Scanner; /** * @author:(LiberHome) * @date:Created in 2019/3/5 21:08 * @description ...

  9. 编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串。 但是要保证汉字不被截半个,如“我ABC”4,应该截为“我AB”,输入“我ABC汉DEF”,6,应该输出为“我ABC”而不是“我ABC+汉的半个”。

    一.需要分析 1.输入为一个字符串和字节数,输出为按字节截取的字符串--->按照字节[byte]截取操作字符串,先将String转换成byte类型 2.汉字不可以截半--->汉字截半的话对 ...

随机推荐

  1. oracle系统参数修改

    create pfile='/home/oracle/sss.ora' from spfile; create spfile from pfile='/home/oracle/sss.ora'; al ...

  2. openstack外篇之认识mysql授权及一些操作

    openstack外篇之认识mysql授权及一些操作  http://www.aboutyun.com/thread-11405-1-1.html

  3. linux系统下memcached启动正常但程序无法连接的问题解决

    在虚拟机linux安装好memcached之后,试着用java程序连接一下memcached的服务端,但却出现了以下错误 com.schooner.MemCached.SchoonerSockIOPo ...

  4. jquery easyui filebox 上传附件 + asp.net后台

    form必须加这个属性enctype="multipart/form-data",否则后台获取不到文件 <script> function uploadFiles() ...

  5. (转载)iscroll.js的使用

    入门 Scroll是一个类,每个需要使用滚动功能的区域均要进行初始化.每个页面上的iScroll实例数目在设备的CPU和内存能承受的范围内是没有限制的. 尽可能保持DOM结构的简洁.iScroll使用 ...

  6. MySQL必知必会笔记<2>

    [英]ben Forta著 5 1.0  *使用扩展查询* |---->select note from table   where Match(note) Against('anl'); |- ...

  7. c语言 文件写入和读取

    #include<stdio.h> #include<stdlib.h> #include<string.h> #define N 10 struct studen ...

  8. QT5中QString与char *的相互转换

    以例子说明: #include <QApplication> #include <QDebug> #include <QString> #include <Q ...

  9. WPF Bug清单之(13)——应该出现却没有出现的ListView水平滚动条

    转载地址:http://www.cnblogs.com/nankezhishi/archive/2010/03/17/wpfbug13.html 我们知道ListView在内容超出控件本身范围时,默认 ...

  10. 客户端数据持久化解决方案: localStorage

    客户端数据持久化解决方案: localStorage localStorage主要用来替代cookie,解决cookie读写困难.容量有限的问题. localStorage有以下几个特点 localS ...