• C语言:将字符串中的前导*号全部移到字符串的尾部。


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

     1 #include <stdio.h>
     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 != '')
    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 = '';
    34 }
    35 
    36 void main()
    37 {  char  s[81];  int  n=0; void NONO ();
    38    printf("Enter a string:
    ");gets(s);
    39    fun( s );
    40    printf("The string after moveing:
    ");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
    ", s) ;    
    53   }
    54   fclose(in) ;
    55   fclose(out) ;
    56 }
  • 相关阅读:
    系统调用简单总结
    系统调用原理详解
    总结:c 语言与Linux操作系统的关系
    poj3171 Cleaning Shifts
    洛谷P1032 字串变换
    poj3662 Telephone Lines
    洛谷P1073 最优贸易
    Uva1330/poj1964 City Game
    poj2559/SP1805 Largest Rectangle in a Histogram
    洛谷 P1196 [NOI2002]银河英雄传说
  • 原文地址:https://www.cnblogs.com/ming-4/p/10583369.html
Copyright © 2020-2023  润新知