《C Primer Plus》第六 第十一章编程练习答案.docx
《《C Primer Plus》第六 第十一章编程练习答案.docx》由会员分享,可在线阅读,更多相关《《C Primer Plus》第六 第十一章编程练习答案.docx(17页珍藏版)》请在三一办公上搜索。
1、C Primer Plus第六 第十一章编程练习答案1 #include #include #defineSIZE 100 void input(char *, int ); int main(void) chararrSIZE; int n; puts(input the number of n:); scanf(%d, &n); getchar; puts(input your string: ); input(arr, n); printf(%sn, arr); getchar; return 0; void input(char *Arr, intlen) inti; for (i=0
2、; ilen; i+) *(Arr+i)=getchar; *(Arr+i)=0; while(getchar !=n) continue; 2. #include #include #defineSIZE 100 void input(char *, int ); int main(void) chararrSIZE; int n; puts(input the number of n:); scanf(%d, &n); getchar; puts(input your string: ); input(arr, n); puts(arr); getchar; return 0; void
3、input(char *Arr, intlen) inti; for (i=0; ilen; i+) *(Arr+i)=getchar; if (*(Arr+i) = | *(Arr+i)=t break; *(Arr+i)=0; while(getchar !=n) continue; 3. #include #include #defineSIZE 100 | *(Arr+i)= n) void input(char * ); int main(void) chararrSIZE; puts(input your string: ); input(arr); puts(arr); getc
4、har; return 0; void input(char *Arr) charch; inti=1; do ch=getchar; while(ch = | ch =t | ch =n); Arr0=ch; while( (ch=getchar) &( ch!= &ch!=t&ch!=n) Arri=ch; i+; Arri=0; while (getchar!=n) continue; 4. #include #include #defineSIZE 100 void input(char *, int ); int main(void) chararrSIZE; int n; puts
5、(input the number of n:); scanf(%d, &n); puts(input your string: ); input(arr, n); puts(arr); getchar; return 0; void input(char *Arr, intlen) charch; inti=1; do ch=getchar; while(ch = | ch =t | ch =n); Arr0=ch; while( (ch=getchar) &( ch!= &ch!=t&ch!=n) &ilen) Arri=ch; i+; Arri=0; while (getchar!=n)
6、 continue; 5. #include #include #defineSIZE 100 char *find(char *, char ); int main(void) chararrSIZE; charch; char *ps; while(1) puts(input a string:); fgets(arr, 100, stdin); puts(input a character:); ch=getchar; ps=find(arr, ch); if(ps) puts(Find the character!); else puts(Cont find the charcter!
7、); getchar; getchar; return 0; char *find(char *Arr, charc) intlen=strlen(Arr); char *p=Arr; inti; for (i=0; ilen; i+) if (c= *p) return p; p+; if (i=len) returnNULL; return 0; 6. #include #include #defineSIZE 100 intis_within(char *, char ); int main(void) chararrSIZE; charch; int re; while(1) puts
8、(input a string:); fgets(arr, 100, stdin); puts(input a character:); ch=getchar; re=is_within(arr, ch); if(re) puts(Find the character!); else puts(Cont find the charcter!); getchar; getchar; return 0; intis_within(char *Arr, charc) intlen=strlen(Arr); char *p=Arr; inti; for (i=0; ilen; i+) if (c= *
9、p) return 1; p+; if (i=len) return 0; else return -1; 7. #include #include #defineSIZE 20 char *mystrncpy(char *, char *, int ); int main(void) char s1SIZE; char s2SIZE; char *ps; int n; while(1) puts(input string s2:); gets(s2); puts(input string s1:); gets(s1); puts(Input the number of n:); scanf(
10、%d, &n); ps=mystrncpy(s1,s2, n ); puts(After copy:); puts(ps); getchar; getchar; return 0; char *mystrncpy(char *dst, char *src, intlen) inti; char *p1, *p2; int L=strlen(src); p2=src; p1=dst; for (i=0; i(Llen? L:len); i+) *(p1+i)=*(p2+i); return p1; 8. #include #include #defineSIZE 20 char *string_
11、in(char *, char * ); int main(void) char s1SIZE; char s2SIZE; char *ps; while(1) puts(input string s2:); gets(s2); puts(input string s1:); gets(s1); ps=string_in(s1,s2); if (ps) puts(Find it!); else puts(Cont find it!); getchar; getchar; return 0; char *string_in(char *s1, char *s2) int len1, len2;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C Primer Plus C Primer Plus第六 第十一章编程练习答案 Plus 第六 第十一 编程 练习 答案

链接地址:https://www.31ppt.com/p-3171061.html