当前位置:   article > 正文

明解C语言入门篇 练习题第11章_void deldigit(char *s)

void deldigit(char *s)

11-1 

  1. #include <stdio.h>
  2. int main(void)
  3. {
  4. char *p = "123";
  5. printf("p = \"%s\"\n", p);
  6. p = "456"+1;
  7. printf("p = \"%s\"\n", p);
  8. return 0;
  9. }

11-2

  1. #include <stdio.h>
  2. int main(void)
  3. {
  4. char a[][5]= {"LISP","C","Ada"};
  5. char *p[]= {"PAUL","X","MAC"};
  6. int q;
  7. int o;
  8. q=sizeof(a)/sizeof(a[0]);
  9. o=sizeof(p)/sizeof(p[0]);
  10. printf("a数组的字符串个数为%d, p数组的字符串个数为%d",q,o);
  11. return 0;
  12. }

11-3

  1. #include <stdio.h>
  2. char *str_copy(char *d, const char *s)
  3. {
  4. char *t = d;
  5. while (*d++ =*s++);
  6. return t;
  7. }
  8. int main(void)
  9. {
  10. char str[128] = "ABC";
  11. char tmp[128];
  12. printf("str = \"%s\"\n", str);
  13. printf("复制的是:", tmp);
  14. scanf("%s", tmp);
  15. puts("复制了。");
  16. printf("str = \"%s\"\n", str_copy(str, tmp));
  17. return 0;
  18. }

 

11-4  

  1. #include <stdio.h>
  2. void put_string(const char*s)
  3. {
  4. while(*s)
  5. {
  6. printf("%c",*s);
  7. *s++;
  8. }
  9. return;
  10. }
  11. int main(void)
  12. {
  13. char sh[] = "123";
  14. put_string(sh);
  15. printf("\n");
  16. return 0;
  17. }

11-5 

  1. #include <stdio.h>
  2. #include <string.h>
  3. int str_chnum(const char*s,int c)
  4. {
  5. int num=0;
  6. while(*s)
  7. {
  8. if(*s==c)
  9. {
  10. num++;
  11. }
  12. *s++;
  13. }
  14. return num;
  15. }
  16. int main(void)
  17. {
  18. char s[128];
  19. char c;
  20. printf("请输入一个字符串:");
  21. scanf("%s",s);
  22. getchar();
  23. printf("请输入一个字符:");
  24. scanf("%c",&c);
  25. printf("\n");
  26. printf("该字符串中%c的个数为:%d\n",c,str_chnum(s,c));
  27. return 0;
  28. }

11-6

  1. #include <stdio.h>
  2. #include <string.h>
  3. int *str_chr(const char*s,int c)
  4. {
  5. char *t;
  6. while(*s)
  7. {
  8. if(*s==c)
  9. {
  10. t=s;
  11. break;
  12. }
  13. else
  14. {
  15. t=NULL;
  16. }
  17. *s++;
  18. }
  19. return t;
  20. }
  21. int main(void)
  22. {
  23. char s[128];
  24. char c;
  25. printf("请输入一个字符串:");
  26. scanf("%s",s);
  27. getchar();
  28. printf("请输入一个字符:");
  29. scanf("%c",&c);
  30. printf("\n");
  31. printf("该字符串中%c的指针为:%p\n",c,str_chr(s,c));
  32. return 0;
  33. }

11-7 

  1. #include <stdio.h>
  2. #include <string.h>
  3. void str_toupper(char*s)
  4. {
  5. while(*s)
  6. {
  7. *s=toupper(*s);
  8. s++;
  9. }
  10. return;
  11. }
  12. void str_tolower(char*s)
  13. {
  14. while(*s)
  15. {
  16. *s = tolower(*s);
  17. s++;
  18. }
  19. return;
  20. }
  21. int main(void)
  22. {
  23. char s[128];
  24. printf("请输入一串字符:");
  25. scanf("%s",s);
  26. printf("变成大写为:");
  27. str_toupper(s);
  28. printf("%s",s);
  29. printf("\n");
  30. printf("变成小写为:");
  31. str_tolower(s);
  32. printf("%s",s);
  33. printf("\n");
  34. return 0;
  35. }

11-8

  1. #include <stdio.h>
  2. #include <string.h>
  3. void del_digit(char*s)
  4. {
  5. while(*s)
  6. {
  7. if((*s>='a')&&(*s<='z')||(*s>='A')&&(*s<='Z'))
  8. {
  9. putchar(*s);
  10. }
  11. s++;
  12. }
  13. return;
  14. }
  15. int main(void)
  16. {
  17. char s[128];
  18. printf("请输入一串字符:");
  19. scanf("%s",s);
  20. printf("删除数字字符后:");
  21. del_digit(s);
  22. printf("\n");
  23. return 0;
  24. }

11-9 不做

11-10不做

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/算法编织者/article/detail/62781
推荐阅读
相关标签
  

闽ICP备14008679号