C语言编程>第十八周 ⑥ 请补充main函数,该函数的功能是:把字符串str1中的非空格字符拷贝到字符串str2中。

例题:请补充main函数,该函数的功能是:把字符串str1中的非空格字符拷贝到字符串str2中。

例如,若字符串str1= “Just a test!”,则拷贝后的字符串str2= “Justatest!
注意:仅在横线上填写所需的若干表达式或语句,请勿改动函数中的其它任何内容。

代码如下:

#include<stdio.h>
#define LEN 80
main()
{
    
    
	static char s1[LEN]="Just a test!";
	char s2[LEN];
	int i=0,j=0;
	printf("s1:");
	puts(s1);
	while(s1[i])
	{
    
    
		if(s1[i]!=' ')
			s2[j++]=s1[i];
		i++;
	}
	printf("\ns2:");
	for(i=0;i<j;i++)
		printf("%c",s2[i]);
	printf("\n");
}

输出运行窗口如下:
在这里插入图片描述

越努力越幸运!
加油,奥力给!!!

猜你喜欢

转载自blog.csdn.net/qq_45385706/article/details/112381727
今日推荐