问题描述:写一段程序,就是一串字符,如:welcome to bit!!!!!!.然后由初始符###################开始变,变成w###############!,然后再是we###########!!,最后变成welcome to bit!!!!!!!;
问题分析:
首先是定义字符串
char str[] = "welcome to bit!!!!!!";//{'w','e','l','c','o','m','e',' ','t','o',' ','b','i','t','!','!','!' ,'!' ,'!' ,'!' ,0};
int a = 0;
char str1[] = "####################";//{'#','#','#','#','#' ,'#' ,'#' ,'#' ,'#' ,'#' ,'#' ,'#' ,'#' ,'#' ,'#' ,'#' ,'#' ,'#' ,'#' ,'#' ,0};
//scanf("%s",&str);
int shuru = 0;
算出字符串str的长度
a = strlen(str) ;
然后利用一个循环,让str1中的字符从第一个和最后一个开始等于str中的相应字符
for (int i = 0; i <= a/2; i++)//循环
{
printf("%s\n", str1);//先打印一下初始符号#
str1[i] = str[i];//str1的第一个字符等于str的第一个字符然后依次向后
str1[19 - i] = str[19 - i];//str1的最后一个字符等于str的最后一个字符,然后依次向前
//scanf("%d", &shuru);
Sleep(1000);//每过一秒中执行一次
system("cls");//执行系统命令-cls:清空屏幕,使显示效果更好
}
附全代码:
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <stdlib.h>
//#include <system.h>
int main()
{
//welcome come to bit
char str[] = "welcome to bit!!!!!!";//{'w','e','l','c','o','m','e',' ','t','o',' ','b','i','t','!','!','!' ,'!' ,'!' ,'!' ,0};
int a = 0;
char str1[] = "####################";//{'#','#','#','#','#' ,'#' ,'#' ,'#' ,'#' ,'#' ,'#' ,'#' ,'#' ,'#' ,'#' ,'#' ,'#' ,'#' ,'#' ,'#' ,0};
//scanf("%s",&str);
int shuru = 0;
a = strlen(str) ;
//printf("%s\n", str);
for (int i = 0; i <= a/2; i++)
{
printf("%s\n", str1);
str1[i] = str[i];
str1[19 - i] = str[19 - i];
//scanf("%d", &shuru);
Sleep(1000);
system("cls");//执行系统命令-cls:清空屏幕
}
printf("%s\n", str);
return 0;