一、删除前缀 '*'

 1 #include<iostream>
 2 #include<cstdio>
 3 
 4 using namespace std;
 5 
 6 //主函数
 7 int main()
 8 {
 9     char chr[20],*b,*p; //字符串缓冲区;字符串头指针;字符串临时指针 
10     int chr_num=0,b_num=0; //输入的字符串中字符的个数;输入的字符串中前缀 * 的个数
11     int i;
12     
13     //输入 
14     cout<<"Please input a string:"<<endl; 
15     gets(chr);
16     
17     //统计输入的字符串中字符的个数 
18     p=chr; // p 指向字符串的第一个字符 
19     while(*p++)
20     {
21         chr_num++;
22     }
23 
24     //统计输入的字符串中前缀 * 的个数
25     b=chr; // b 指向字符串的第一个字符 
26     while(*b++=='*')
27     {
28         b_num++;
29     }
30     
31     //删除输入的字符串中的前缀 *  
32     for(i=0;i<chr_num-b_num;i++)
33     {
34         chr[i]=chr[i+b_num];
35     }
36     chr[i]='\0';
37     
38     //输出
39     cout<<"The result:"<<endl;
40     puts(chr);
41     
42     return 0; 
43 }
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-21
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-03
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案