编写一个程序实现strcpy函数的功能
#include <stdio.h>
#include <string.h>
#define N 5 char *mycpy(char *s1, char *s2)
{
//数组型
/* int i;
while(s2[i] != '\0') {
s1[i] = s2[i];
i++;
}
s1[i] = '\0';
return s1; */
//指针型
char *p = s1;
while(*s2 != '\0') {
*s1 = *s2;
s1++;
s2++;
}
*s1 = '\0';
return p;
} int main()
{
char s1[];
char s2[];
// gets(s1);
// gets(s2);
fgets(s1, N, stdin);
if(s1[strlen(s1) - ] == '\n') { // 去掉换行符
s1[strlen(s1) - ] = '\0';
}
fflush(stdin); //清空缓冲区(具体请看gets和fgets函数的区别)
fgets(s2, N, stdin);
if(s2[strlen(s2) - ] == '\n') { // 去掉换行符
s2[strlen(s2) - ] = '\0';
}
printf("%s", mycpy(s1, s2)); return ;
}
编写一个程序实现strcpy函数的功能的更多相关文章
- 编写一个程序实现strcmp函数的功能
写自己的strcat函数------→mycmp #include <stdio.h> #include <string.h> #define N 5 int mycmp(ch ...
- 编写一个程序实现strcat函数的功能
写自己的strcat函数------→mycat #include <stdio.h> #include <string.h> #define N 5 char *mycat( ...
- 编写一个程序实现strlen函数的功能
写自己的 strlen 函数-----→ mystrlen #include <stdio.h> #include <string.h> #define N 100 int m ...
- python练习:编写一个程序,要求用户输入10个整数,然后输出其中最大的奇数,如果用户没有输入奇数,则输出一个消息进行说明。
python练习:编写一个程序,要求用户输入10个整数,然后输出其中最大的奇数,如果用户没有输入奇数,则输出一个消息进行说明. 重难点:通过input函数输入的行消息为字符串格式,必须转换为整型,否则 ...
- python练习:编写一个程序,要求用户输入一个整数,然后输出两个整数root和pwr,满足0<pwr<6,并且root**pwr等于用户输入的整数。如果不存在这样一对整数,则输入一条消息进行说明。
python练习:编写一个程序,要求用户输入一个整数,然后输出两个整数root和pwr,满足0<pwr<6,并且root**pwr等于用户输入的整数.如果不存在这样一对整数,则输入一条消息 ...
- 编写一个程序,求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( ...
- 面试题之java 编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串。 要求不能出现截半的情况
题目:10. 编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串. 但是要保证汉字不被截半个,如"我ABC"4,应该截为"我AB",输 ...
- 已知一个正整数m,编写一个程序求m的反序数(待消化)
import java.util.Scanner; /** * @author:(LiberHome) * @date:Created in 2019/3/5 21:08 * @description ...
- 编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串。 但是要保证汉字不被截半个,如“我ABC”4,应该截为“我AB”,输入“我ABC汉DEF”,6,应该输出为“我ABC”而不是“我ABC+汉的半个”。
一.需要分析 1.输入为一个字符串和字节数,输出为按字节截取的字符串--->按照字节[byte]截取操作字符串,先将String转换成byte类型 2.汉字不可以截半--->汉字截半的话对 ...
随机推荐
- iOS断点及打印日志
首先,最简单的断点就是在Xcode项目文件中任意一行行号那点一下,就是加了一个断点 再次点击会变成浅蓝色,表示disable掉了 disable掉的断点不会起作用,但会在左上角蓝色的标签那留下记录,这 ...
- Java中创建对象的5种方式 &&new关键字和newInstance()方法的区别
转载:http://www.kuqin.com/shuoit/20160719/352659.html 用最简单的描述来区分new关键字和newInstance()方法的区别:newInstance: ...
- HDU 1027 - Ignatius and the Princess II
第 m 大的 n 个数全排列 DFS可过 #include <iostream> using namespace std; int n,m; ]; bool flag; ]; void d ...
- Qt编程学习网站
http://blog.csdn.net/k122769836/article/details/8637677 QT - little_su - 博客频道 - CSDN.NET Qt - 1+1=2 ...
- 转 jquery插件--241个jquery插件—jquery插件大全
241个jquery插件—jquery插件大全 jquery插件jqueryautocompleteajaxjavascriptcoldfusion jQuery由美国人John Resig创建,至今 ...
- HttpServletRequest 报错 myeclipese支持tomcat
做WEB项目的时候,别人拷贝了一份源码给你导入myeclipse结果发现一堆报错 HttpServletRequest 一排红色波浪线..... 这个原因主要是没有tomcat下的一个jar包 se ...
- OpenCV2.4.9+VS2012安装与配置
需要下载并安装Visual Studio 2012 然后在OpenCV官网下载安装OpenCV2.4.9 for Windows,网址为http://opencv.org/downloads.html ...
- java比较器 之compareable 和comparato比较
compareable 测试类import java.util.Set; import java.util.TreeSet; public class Test { public static voi ...
- The solution for "Eclipse is running in a JRE, but a JDK is required"
Open the eclipse folder and access the eclipse.ini file: Before change it ,you will find it don’t ...
- 如何利用多核CPU来加速你的Linux命令 — awk, sed, bzip2, grep, wc等
http://blog.chinaunix.net/uid-20662820-id-4023733.html http://www.faqs.org/faqs/snmp-faq/part2/ http ...