`

百度笔试查错题,n多错误,慢慢找吧

阅读更多

2. (15 分)下面一段代码,想在调用 f2(1) 时打印 err1,调用 f2(2) 时打印 err4,但是代码中有一些问题,请做尽可能少的修改使之正确。
1 static int f1( const char *errstr, unsigned int flag ) {
2   int copy, index, len;
3   const static char **__err = { "err1", "err2", "err3", "err4" };
4
5   if( flag & 0x10000 )
6     copy = 1;
7   index = ( flag & 0x300000 ) >> 20;
8
9   if( copy ) {
10     len = flag & 0xF;
11     errstr = malloc( len );
12     if( errstr = NULL )
13       return -1;
14     strncpy( errstr, __err[index], sizeof( errstr ) );
15   } else
16     errstr = __err + index;
17 }
18
19 void f2( int c ) {
20   char *err;
21
22   swtch( c ) {
23   case 1:
24     if( f1( err, 0x110004 ) != -1 )
25       printf( err );
26   case 2:
27     if( f2( err, 0x30000D ) != -1 )
28       printf( err );
29   }
30 }
========

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics