赞
踩
11-1
- #include <stdio.h>
-
- int main(void)
- {
- char *p = "123";
-
- printf("p = \"%s\"\n", p);
-
- p = "456"+1;
-
- printf("p = \"%s\"\n", p);
-
- return 0;
- }
11-2
- #include <stdio.h>
-
- int main(void)
- {
- char a[][5]= {"LISP","C","Ada"};
- char *p[]= {"PAUL","X","MAC"};
- int q;
- int o;
- q=sizeof(a)/sizeof(a[0]);
- o=sizeof(p)/sizeof(p[0]);
- printf("a数组的字符串个数为%d, p数组的字符串个数为%d",q,o);
- return 0;
- }
11-3
- #include <stdio.h>
-
- char *str_copy(char *d, const char *s)
- {
- char *t = d;
-
- while (*d++ =*s++);
- return t;
- }
-
- int main(void)
- {
- char str[128] = "ABC";
- char tmp[128];
-
- printf("str = \"%s\"\n", str);
-
- printf("复制的是:", tmp);
- scanf("%s", tmp);
-
- puts("复制了。");
- printf("str = \"%s\"\n", str_copy(str, tmp));
-
- return 0;
- }
11-4
- #include <stdio.h>
-
- void put_string(const char*s)
- {
- while(*s)
- {
- printf("%c",*s);
- *s++;
- }
- return;
- }
-
- int main(void)
- {
- char sh[] = "123";
- put_string(sh);
- printf("\n");
- return 0;
- }
11-5
- #include <stdio.h>
- #include <string.h>
-
- int str_chnum(const char*s,int c)
- {
- int num=0;
- while(*s)
- {
- if(*s==c)
- {
- num++;
- }
- *s++;
- }
- return num;
- }
-
- int main(void)
- {
- char s[128];
- char c;
- printf("请输入一个字符串:");
- scanf("%s",s);
- getchar();
- printf("请输入一个字符:");
- scanf("%c",&c);
- printf("\n");
- printf("该字符串中%c的个数为:%d\n",c,str_chnum(s,c));
- return 0;
- }
11-6
- #include <stdio.h>
- #include <string.h>
-
- int *str_chr(const char*s,int c)
- {
- char *t;
- while(*s)
- {
- if(*s==c)
- {
- t=s;
- break;
- }
- else
- {
- t=NULL;
- }
- *s++;
- }
- return t;
- }
-
- int main(void)
- {
- char s[128];
- char c;
- printf("请输入一个字符串:");
- scanf("%s",s);
- getchar();
- printf("请输入一个字符:");
- scanf("%c",&c);
- printf("\n");
- printf("该字符串中%c的指针为:%p\n",c,str_chr(s,c));
- return 0;
- }
11-7
- #include <stdio.h>
- #include <string.h>
-
- void str_toupper(char*s)
- {
- while(*s)
- {
- *s=toupper(*s);
- s++;
- }
- return;
- }
-
- void str_tolower(char*s)
- {
- while(*s)
- {
- *s = tolower(*s);
- s++;
- }
- return;
- }
-
- int main(void)
- {
- char s[128];
- printf("请输入一串字符:");
- scanf("%s",s);
-
- printf("变成大写为:");
- str_toupper(s);
- printf("%s",s);
- printf("\n");
-
- printf("变成小写为:");
- str_tolower(s);
- printf("%s",s);
- printf("\n");
-
- return 0;
-
- }
11-8
- #include <stdio.h>
- #include <string.h>
-
- void del_digit(char*s)
- {
- while(*s)
- {
- if((*s>='a')&&(*s<='z')||(*s>='A')&&(*s<='Z'))
- {
- putchar(*s);
- }
-
- s++;
- }
- return;
- }
-
-
-
- int main(void)
- {
- char s[128];
- printf("请输入一串字符:");
- scanf("%s",s);
-
- printf("删除数字字符后:");
- del_digit(s);
- printf("\n");
-
- return 0;
-
- }
11-9 不做
11-10不做
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。