《《c primer plus》第六版 第十一章编程练习答案》由会员分享,可在线阅读,更多相关《《c primer plus》第六版 第十一章编程练习答案(19页珍藏版)》请在金锄头文库上搜索。
1、1#include#include#define SIZE 100void input(char *, int );int main(void)char arrSIZE;int n;puts(input the number of n:);scanf(%d, getchar();puts(input your string: );input(arr, n);printf(%sn, arr);getchar();return 0;void input(char *Arr, int len)int i;for (i=0; i#include#define SIZE 100void input(ch
2、ar *, int );int main(void)char arrSIZE;int n;puts(input the number of n:);scanf(%d, getchar();puts(input your string: );input(arr, n);puts(arr);getchar();return 0;void input(char *Arr, int len)int i;for (i=0; i#include#define SIZE 100void input(char * );int main(void)char arrSIZE;puts(input your str
3、ing: );input(arr);puts(arr);getchar();return 0;void input(char *Arr)char ch;int i=1;doch=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#define SIZE 100void input(char *, int );int main(void)
4、char arrSIZE;int n;puts(input the number of n:);scanf(%d, puts(input your string: );input(arr, n);puts(arr);getchar();return 0;void input(char *Arr, int len)char ch;int i=1;doch=getchar();while(ch = | ch =t | ch =n);Arr0=ch;while( (ch=getchar() &( ch!= & ch!=t & ch!=n) & i#include#define SIZE 100cha
5、r *find(char *, char );int main(void)char arrSIZE;char ch;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!);elseputs(Cont find the charcter!);getchar();getchar();return 0;char *find(char *Arr, char c)i
6、nt len=strlen(Arr);char *p=Arr;int i;for (i=0; i#include#define SIZE 100int is_within(char *, char );int main(void)char arrSIZE;char ch;int re;while(1)puts(input a string:);fgets(arr, 100, stdin);puts(input a character:);ch=getchar();re=is_within(arr, ch);if(re)puts(Find the character!);elseputs(Con
7、t find the charcter!);getchar();getchar();return 0;int is_within(char *Arr, char c)int len=strlen(Arr);char *p=Arr;int i;for (i=0; i#include#define SIZE 20char *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 str
8、ing s1:);gets(s1);puts(Input the number of n:);scanf(%d, ps=mystrncpy(s1,s2, n );puts(After copy:);puts(ps);getchar();getchar();return 0;char *mystrncpy(char *dst, char *src, int len)int i;char *p1, *p2;int L=strlen(src);p2=src;p1=dst;for (i=0; i#include#define SIZE 20char *string_in(char *, char *
9、);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!);elseputs(Cont find it!);getchar();getchar();return 0;char *string_in(char *s1, char *s2)int len1, len2;int i, j, temp;char *p1=s1;char *p
10、2=s2;len1=strlen(s1);len2=strlen(s2);if (*p1=0 | *p2 =0) return NULL;for (i=0; i(len1-len2) return NULL;9#include#include#define SIZE 20void fun(char *);int main(void)char arrSIZE;while(1)puts(input a string:);gets(arr);fun(arr);puts(arr);getchar();getchar();return 0;void fun(char *Arr)char *p=Arr;i
11、nt len=strlen(Arr);int i;char ch;for (i=0; i#include#define SIZE 20void fun(char *);int main(void)char arrSIZE;while(1)puts(input a string:);gets(arr);if (arr0=n) break;fun(arr);puts(arr);getchar();getchar();return 0;void fun(char *Arr)int i, j;char tempSIZE;i=j=0;while(Arri!=0)if (Arri!= )tempj=Arr
12、i;j+;i+;strcpy(Arr, temp);Arrj=0;11.#include#include#define SIZE 20#define LIM 3void display(char *String);void Ascii( char *String);void Length(char *String);void FirstC(char *String);int First_word(char String);int main(void)char inputLIMSIZE;char ch;char *ptrLIM;while (1)int ct=0;puts(please inpu
13、t 10 strings:);while (ct0)p=Stringj;Stringj=Stringj+1;Stringj+1=p;display(String);void Length(char *String)char *p;int i,j;for (i=0; istrlen(Stringj+1)p=Stringj;Stringj=Stringj+1;Stringj+1=p;display(String);int First_word(char String)int i=0;while (Stringi != )i+;return i;void FirstC(char *String)ch
14、ar *p;int i,j;for (i=0; iFirst_word(Stringj+1)p=Stringj;Stringj=Stringj+1;Stringj+1=p;display(String);12#include#include#includeint main(void)int ch;int word, large, small, punctuation, num, begin;word=large=small=punctuation=num=begin=0;while( (ch=getchar() != EOF) if (isdigit(ch)num+;if (ispunct(c
15、h)punctuation+;if (isupper(ch)large+;if (islower(ch)small+;if ( isalpha(ch)if (begin=0)word+;begin=1;elsebegin=0;printf(words=%d, large=%d, small=%d, punc=%d, num=%dn, word, large, small, punctuation, num);getchar();return 0;13.#include#includevoid Reverse(char *, int );int main(void)char str100;int len;puts(Enter a string:);gets(str);len=str