6-5——指针(连接字符串)编码练习——请教优化

Posted 歌咏^0^

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了6-5——指针(连接字符串)编码练习——请教优化相关的知识,希望对你有一定的参考价值。

指针(连接字符串)

题目描述

将2行英文连接后输出。不能使用strcat函数。

 

要求:编写函数f(char *s1,char *s2,char *s3),将字符指针*s1中字符与字符指针*s2中字符连接到到字符指针*s3中。

输入

 输入包括2行英文。

 

输出

将2行英文连接后输出。

样例输入

Problems involving the computation of exact values of very large magnitude and precision are common.
For example, the computation of the national debt is a taxing experience for many computer systems.

样例输出

Problems involving the computation of exact values of very large magnitude and precision are common.For example, the computation of the national debt is a taxing experience for many computer systems.

 

#include <stdio.h>

void f(char* s1, char* s2, char* s3)
{
	int i = 0, j = -1;
	char* pc = s3;

	while (s1[i] != '\\0')
	{
		pc[i] = s1[i];
		i++;
	}

	do
	{
		j++;
		pc[i] = s2[j];
		i++;
	} 	while (s2[j] != '\\0');
}

int main()
{
	char str1[] = "Problems involving the computation of exact values of very large magnitude and precision are common.";
	char str2[] = "For example, the computation of the national debt is a taxing experience for many computer systems.";
	char str3[200] = {};
	f(str1, str2, str3);
	printf("%s\\n", str3);

	return 0;
}

 

^o^求点赞求、关注,谢谢,感激不尽

以上是关于6-5——指针(连接字符串)编码练习——请教优化的主要内容,如果未能解决你的问题,请参考以下文章

指针练习

请教关于UTF-8编码问题~~~

近期开发项目中用到的编码小技巧汇总说明

Python读取cvs文件报错:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb1 in position 6(代

请教如何识别url中的中文,并把中文进行转义

请教:如何将写好的类封装成dll文件