请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,此工程中含有一个源程序文件proj2.cpp。函数char*GetNum(char*src,ehar*buf)从src开始扫描下一个数字字符序列,并将其作为一个字符串取出放人字符串空

admin2020-10-21  41

问题 请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,此工程中含有一个源程序文件proj2.cpp。函数char*GetNum(char*src,ehar*buf)从src开始扫描下一个数字字符序列,并将其作为一个字符串取出放人字符串空间buf中。函数返回扫描的终止位置,如果返回NULL表示没有扫描到数字字符序列。
    运行程序时,如果输入的一行字符序列是
    ABC012XYZ378MN274WS
则输出为:
    Digit string 1 is 012
    Digit string 2 is 378
    Digit string 3 is 274
    注意:只在横线处编写适当代码,不要删除或移动“//****found****”。
1    //proj2.cpp
2    #include
3    using namespace std;
4    char*GetNum(char*src,char*buf)
5    {
6    while(*src!=’\0’)
7    {
8    if(isdigit(*sre))break;
9    src++;
10    }
11    if(*src=:’\0’)
12    //********found********
13    _______;
14    while(*sre!=’\0’&&isdigit(*sre))
15    {
16     //********found********
17    _______;
18    buf++;
19   src++;
20  }
21  *buf=’\0’;
22  return src;
23  }
24  int main()
25  {
26  char str[100],digits[20];
27  cin.getline(str,100);
28  char*p=str;
29  int i=1;
30  while((P=GetNum(p,digits))t=NULL)
31  {
32    cout<<"Digit string"<33    //********found********
34    ______;
35   }
36    return 0;
37    }

选项

答案(1)return NULL (2)*buf=*src (3)i++

解析 (1)主要考查考生对if语句的掌握,由判断条件if(*src==’\0’),说明字符串src为空,则返回NULL即可。
    (2)主要考查考生对while循环语句的掌握,while语句的循环条件为*src!=’\0’&&isdigit(*src),该条件是指,若字符串src不为空并且水src指向的字符为数字字符,则进行循环。题目要求把数字字符放入字符串buf中,因此为*buf=*src。
    (3)主要考查考生对while循环语句的掌握,从上一行语句cout<<"Digit string"<
转载请注明原文地址:https://kaotiyun.com/show/6yyp777K
0

随机试题
最新回复(0)