c语言中把每个字母向前移1位,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
總結
以上是生活随笔為你收集整理的c语言中把每个字母向前移1位,C语言:将字符串中的前导*号全部移到字符串的尾部。...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux daemon守护线程,线程8
- 下一篇: c#语言输出字符串长度,根据宽度来决定显