//规定输入的字符串中只包含字母和*号,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