c语言中把每个字母向前移1位,C语言:将字符串中的前导*号全部移到字符串的尾部。...

本文介绍了一个C语言函数,该函数可以将输入字符串中的所有前导*号移至字符串末尾。通过重新组织字符数组实现这一功能,适用于学习C语言字符串操作。

//规定输入的字符串中只包含字母和*号,fun函数:将字符串中的前导*号全部移到字符串的尾部。

1 #include

2 void fun( char *a )

3 {

4 char b[81];

5 char *c,*d;

6 c = a;

7 int i = 0;

8 while (*c == '*')

9 {

10 c++;

11 }

12 d = c;

13 while (*c != '\0')

14 {

15 b[i] = *c;

16 i++;

17 c++;

18 }

19 int e = 0;

20 while (a < d)

21 {

22 b[i] = *a;

23 i++;

24 a++;

25 e++;

26 }

27 a = a - e;

28 for (int j = 0; j < i; j++)

29 {

30 *a = b[j];

31 a++;

32 }

33 *a = '\0';

34 }

35

36 void main()

37 { char s[81]; int n=0; void NONO ();

38 printf("Enter a string:\n");gets(s);

39 fun( s );

40 printf("The string after moveing:\n");puts(s);

41 NONO();

42 }

43 void NONO ()

44 {/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */

45 FILE *in, *out ;

46 int i ; char s[81] ;

47 in = fopen("in.dat","r") ;

48 out = fopen("out.dat","w") ;

49 for(i = 0 ; i < 10 ; i++) {

50 fscanf(in, "%s", s) ;

51 fun(s) ;

52 fprintf(out, "%s\n", s) ;

53 }

54 fclose(in) ;

55 fclose(out) ;

56 }

标签:fun,int,void,C语言,char,++,字符串,前导,out

来源: https://www.cnblogs.com/ming-4/p/10583369.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值