【C编程】将字符串t复制到字符串 s 中

来源:互联网 发布:删除文件的c语言代码 编辑:程序博客网 时间:2024/04/29 00:50

【题目】: 编写一个函数escape( s , t ),将字符串t复制到字符串 s 中,并在复制过程中将换行符、制表符等不可见字符分别转换为/n/t等相应的可见的转义字符序列,并统计复制后字符串的里面大写字母,小写字母,数字各自的数目。

头函数:

void escape(char d[],char s[]);

主函数:

#include<stdio.h>

#define N  10 

#include"3-2.h"

main()

{

char s[N];

char d[N];

int i = 0;

char ch;

printf("please input string!/n");

while((ch = getchar())!=EOF)

s[i++] = ch;

escape(s,d);

}

功能函数:

#include<stdio.h>

#define N  10 

void escape(char s[],char d[])

{

int i,j,k;

int sum_t = 0;

int sum_n = 0;

int count_bzm = 0;

int count_szm = 0;

int count_num = 0;

for(i = 0,j = 0;j < N;i++,j++)

switch(s[j])

{

case '/t':d[i] = '//';

i++ ;

d[i] ='t';

sum_t++;

break;

case '/n':d[i] ='//';

i++;

d[i] = 'n';

sum_n++;

break;

default :d[i] = s[j];

if(s[j]>='a'&&s[j]<='z')

count_szm++;

else if(s[j]>='A'&&s[j]<="Z")

count_bzm++;

else if(s[j]>='0'&&s[j]<='9')

count_num++;

}

 

for(k = 0;k < N+sum_t+sum_n;k++)

printf("%c",d[k]);

printf("/n");

printf("there are %d bigzimu %d smallzimu %d  numer!/n",count_bzm++,count_szm,count_num);

}

 

原创粉丝点击