[关闭]
@fiy-fish 2015-06-25T21:17:52.000000Z 字数 577 阅读 1410

把数组里的单词倒置

C


  1. int main()
  2. {
  3. char *week[7] = {"monday",
  4. "tuesday",
  5. "wednesday",
  6. "thur",
  7. "friday",
  8. "satur",
  9. "sunday" };
  10. char week1[7][10] = {};
  11. for (int i=0; i<7; ++i) {
  12. // printf("1111%p\n", &i);
  13. strcpy(week1[i], week[i]);
  14. }
  15. //将字符串中每个字母倒置
  16. for (int i=0; i<7; ++i) {
  17. // printf("2222%p\n", &i);
  18. int len = (int)strlen(week1[i]);
  19. for (int j=0; j<len/2; ++j) {
  20. printf("%p\n", &j);
  21. char temp = week1[i][j];
  22. week1[i][j]= week1[i][len-1-j];
  23. week1[i][len-1-j] = temp;
  24. }
  25. }
  26. for (int i=0; i<7; ++i) {
  27. // printf("3333%p\n", &i);
  28. printf("%s\n", week1[i]);
  29. }
  30. }
  1. char *week[7] = {"monday",
  2. "tuesday",
  3. "wednesday",
  4. "thur",
  5. "friday",
  6. "satur",
  7. "sunday" };
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注