C++程序设计原理与实践 第十七章部分答案

 1 #include <iostream>
 2 using namespace std;
 3 
 4 void to_lower(char* s)
 5 {
 6     while(*s!='\0')
 7     {
 8         if(*s>='A'&&*s<='Z')
 9             *s+=32;
10         s++;
11     }
12 }
13 
14 char* strdup1(const char*s)
15 {
16     char *p=new char[];
17     cout<<sizeof(s)<<endl;               //////////注意
18     int i;
19     for(i=0;s[i]!='\0';i++)
20     {
21         p[i]=s[i];
22     }
23     p[i]='\0';
24     return p;
25 }
26 
27 char* findx(const char*s,const char*x)
28 {
29     int i=0;
30     while(*s!='\0')
31     {
32         while(*(s+i)==*(x+i)&&*(x+i)!='\0')
33         {
34             i++;
35         }
36         if(*(x+i)=='\0')
37             return (char*)s;
38         else
39             i=0;
40         s++;
41     }
42     return NULL;
43 }
44 
45 int main()
46 {
47     //char c[]="D";
48     //cout<<sizeof(&c)<<endl;          //////////注意
49     //char *p=strdup1(c);
50 //    cout<<p<<endl;
51     char c1[]="fgasdfghj";
52     char c2[]="fgh";
53     cout<<findx(c1,c2);
54     while(1);
55     return 0;
56 
57 }
习题3 4 5
习题10
习题11
习题14
习题12     应用与其他函数参数若是const Link&的话需用后者,因为后者已声明它不改变原有的值  P200  P377
 
 
 

posted on 2014-11-10 22:45  月巴巴  阅读(269)  评论(0)    收藏  举报