鱼C论坛

 找回密码
 立即注册
查看: 2475|回复: 11

[已解决]帮忙debug(简单)

[复制链接]
发表于 2022-10-14 00:51:46 | 显示全部楼层 |阅读模式
50鱼币

  1. #include <stdio.h>
  2. #include <string.h>
  3. #define LIM 2
  4. #define STLEN 100
  5. #define EXIT 5
  6. #define STARS "********************************************************************"

  7. int usr_input(char * strings[]);
  8. int menu();
  9. void prt_strings(char * strings[], int num);
  10. void a_ord(char * strings[], int num);
  11. void len_ord(char * strings[], int num);
  12. void fist_word_len_ord(char * strings[], int num);
  13. char * s_gets(char * Buffer, int maxCount);
  14. int main(void)
  15. {
  16.     int choose, num;
  17.     char usr_strings[LIM + 1][STLEN];
  18.     char *strings[LIM + 1];
  19.     for (int i = 0; i < LIM; i++)
  20.     {
  21.         strings[i] = usr_strings[i];
  22.     }
  23.     num = usr_input(strings);
  24.     while ((choose = menu()) != EXIT)
  25.     {
  26.         switch (choose)
  27.         {
  28.             case 1:
  29.                 prt_strings((char **) usr_strings, num);
  30.                 break;
  31.             case 2:
  32.                 a_ord(strings, num);
  33.                 break;
  34.             case 3:
  35.                 len_ord(strings, num);
  36.                 break;
  37.             case 4:
  38.                 fist_word_len_ord(strings, num);
  39.             default:
  40.                 ;
  41.         }
  42.     }
  43.     return 0;
  44. }

  45. int menu()
  46. {
  47.     puts(STARS);
  48.     int choose;
  49.     puts("1)Print a list of source strings        2)Prints the strings in order in ASCII");
  50.     puts("3)Prints strings in increasing length   4)Prints the string in increasing order of the first word length");
  51.     puts("5)Exit");
  52.     while ((scanf("%d", &choose)) != 1 && choose > 0 && choose < 5)
  53.     {
  54.         puts("Please enter a number of the potion");
  55.     }
  56.     return choose;
  57. }

  58. int usr_input(char * strings[])
  59. {
  60.     puts(STARS);
  61.     int ct = 0;
  62.     printf("Please enter some strings,not more than %d.\n", LIM);
  63.     while (s_gets(strings[ct], STLEN))
  64.     {
  65.         ct++;
  66.         if (ct >= LIM)
  67.             break;
  68.     }
  69.     puts("Entry is complete.");
  70.     return ct;
  71. }

  72. void prt_strings(char *strings[], int num)
  73. {

  74.     puts(STARS);
  75.     for (int i = 0; i < num; i++)
  76.     {
  77.         puts(strings[i]);
  78.     }
  79. }

  80. void a_ord(char * strings[], int num)
  81. {
  82.     puts(STARS);
  83.     char * tmp;
  84.     for (int i = 0; i < num - 1; i++)
  85.     {
  86.         for (int j = i+1; j < num; j++)
  87.         {
  88.             if (strcmp(strings[i], strings[j]) > 0)
  89.             {
  90.                 tmp = strings[i];
  91.                 strings[i] = strings[j];
  92.                 strings[j] = tmp;
  93.             }
  94.         }
  95.     }
  96. }

  97. void len_ord(char * strings[], int num)
  98. {
  99.     char * tmp;
  100.     for (int i = 0; i < num - 1; i++)
  101.     {
  102.         for (int j = i+1; j < num; j++)
  103.         {
  104.             if (strlen(strings[i]) > strlen(strings[j]))
  105.             {
  106.                 tmp = strings[i];
  107.                 strings[i] = strings[j];
  108.                 strings[j] = tmp;
  109.             }
  110.         }
  111.     }
  112. }

  113. void fist_word_len_ord(char * strings[], int num)
  114. {
  115.     char * tmp;
  116.     while (*strings)
  117.     {
  118.         for (int i = 0; strings[i] != NULL; i++)
  119.         {
  120.             for (int j = i+1; j < num - 1; j++) {
  121.                 if ((strchr(strings[i], ' ') - strings[i]) > (strchr(strings[j], ' ') - strings[j]))
  122.                 {
  123.                     tmp = strings[i];
  124.                     strings[i] = strings[j];
  125.                     strings[j] = tmp;
  126.                 }
  127.             }
  128.         }
  129.     }
  130. }

  131. char * s_gets(char Buffer[], int maxCount){
  132.     char * ret_value;
  133.     int i = 0;
  134.     ret_value = fgets(Buffer, maxCount, stdin);
  135.     if (ret_value){
  136.         //替换'\n'为'\0'
  137.         while (Buffer[i] != '\n' && Buffer[i] != '\0') {
  138.             i++;
  139.         }
  140.         if (Buffer[i] == '\n')
  141.             Buffer[i] = '\0';
  142.         else{
  143.             while (getchar() != '\n');
  144.         }
  145.     }
  146.     return ret_value;
  147. }
复制代码
最佳答案
2022-10-14 00:51:47
本帖最后由 jackz007 于 2022-10-14 17:11 编辑

        楼主,你认为这个代码它简单吗?
  1. #include <stdio.h>
  2. #include <string.h>

  3. #define LIM 10
  4. #define STLEN 256

  5. int menu(void)
  6. {
  7.         int m                                                                                                              ;
  8.         printf("     *************************************************\n")                                                 ;
  9.         printf("     **                                             **\n")                                                 ;
  10.         printf("     **                   User Menu                 **\n")                                                 ;
  11.         printf("     **                                             **\n")                                                 ;
  12.         printf("     *************************************************\n\n")                                               ;
  13.         printf("      1. Print a list of source strings \n")                                                               ;
  14.         printf("      2. Prints the strings in order in ASCII\n")                                                          ;
  15.         printf("      3. Prints strings in increasing length\n")                                                           ;
  16.         printf("      4. Prints the string in increasing order of the first word length\n")                                ;
  17.         printf("      5. Exit\n\n")                                                                                        ;
  18.         printf("Please enter a number of the potion : ")                                                                   ;
  19.         for(m = 0 ; m < 1 || m > 5 ;) scanf("%d" , & m)                                                                    ;
  20.         printf("\n")                                                                                                       ;
  21.         return m                                                                                                           ;
  22. }

  23. void operate(char strings[][STLEN], int num)
  24. {
  25.         int d[num] , e[num] , i , j , k , m                                                                                ;
  26.         for(;;) {
  27.                 m = menu()                                                                                                 ;
  28.                 if(m > 0 && m < 5) {
  29.                         for(i = 0 ; i < num ; i ++) d[i] = e[i] = i                                                        ;
  30.                         if (m == 3) {
  31.                                 for(i = 0 ; i < num ; i ++) for(e[i] = j = 0 ; strings[i][j] ; j ++) e[i] ++               ;  // e[i] 保存 strings[i] 的长度
  32.                         } else if(m == 4) {
  33.                                 for(i = 0 ; i < num ; i ++) {
  34.                                         for(j = 0 ; strings[i][j] && strings[i][j] == ' ' ; j ++)                          ;
  35.                                         for(k = j ; strings[i][k] && strings[i][k] != ' ' ; k ++)                          ;
  36.                                         e[i] = k - j                                                                       ;  // e[i] 保存 strings[i] 中第一个 word 的长度
  37.                                 }
  38.                         }
  39.                         if(m > 1 && m < 5) {                                                                                  // 只有功能 2 ~ 4 才需要调整 d 中的元素
  40.                                 for(i = 0 ; i < num - 1 ; i ++) {
  41.                                         for(j = i + 1 ; j < num ; j ++) {
  42.                                                 if(m == 2 && strcmp(strings[d[i]] , strings[d[j]]) > 0 || e[d[i]] > e[d[j]]) { // 排序,m = 2 通过 strcmp() 比较字符串,m = 3、4 比较的都是 e
  43.                                                         k = d[i]                                                           ;
  44.                                                         d[i] = d[j]                                                        ;
  45.                                                         d[j] = k                                                           ;
  46.                                                 }
  47.                                         }
  48.                                 }
  49.                         }
  50.                         for(i = 0 ; i < num ; i ++) printf("%s\n" , strings[d[i]])                                         ;
  51.                         printf("\n\n")                                                                                     ;
  52.                 } else {
  53.                         break                                                                                              ;
  54.                 }
  55.         }
  56. }

  57. int main(void)
  58. {
  59.         int i                                                                                                              ;
  60.         char strings[LIM][STLEN]                                                                                           ;
  61.         printf("Please enter some strings , not more than %d.\n" ,  LIM)                                                   ;
  62.         for(i = 0 ; i < LIM && (gets(strings[i])) ; i ++)                                                                  ;
  63.         operate(strings , i)                                                                                               ;
  64. }
复制代码

        编译、运行实况:
  1. D:\[00.Exerciese.2022]\C>g++ -o x x.c

  2. D:\[00.Exerciese.2022]\C>X
  3. Please enter some strings , not more than 10.
  4. aBCDxyz sdkfhpdgj ' 0968023
  5. ADFDFDGFxv ffk;fjljj 2058-5 2-=3r0-009 Vvvldkjl;jfidflkjg
  6. dfkjlgoi 3086058 l;fj
  7. ^Z
  8.      *************************************************
  9.      **                                             **
  10.      **                   User Menu                 **
  11.      **                                             **
  12.      *************************************************

  13.       1. Print a list of source strings
  14.       2. Prints the strings in order in ASCII
  15.       3. Prints strings in increasing length
  16.       4. Prints the string in increasing order of the first word length
  17.       5. Exit

  18. Please enter a number of the potion : 1

  19. aBCDxyz sdkfhpdgj ' 0968023
  20. ADFDFDGFxv ffk;fjljj 2058-5 2-=3r0-009 Vvvldkjl;jfidflkjg
  21. dfkjlgoi 3086058 l;fj


  22.      *************************************************
  23.      **                                             **
  24.      **                   User Menu                 **
  25.      **                                             **
  26.      *************************************************

  27.       1. Print a list of source strings
  28.       2. Prints the strings in order in ASCII
  29.       3. Prints strings in increasing length
  30.       4. Prints the string in increasing order of the first word length
  31.       5. Exit

  32. Please enter a number of the potion : 2

  33. ADFDFDGFxv ffk;fjljj 2058-5 2-=3r0-009 Vvvldkjl;jfidflkjg
  34. aBCDxyz sdkfhpdgj ' 0968023
  35. dfkjlgoi 3086058 l;fj


  36.      *************************************************
  37.      **                                             **
  38.      **                   User Menu                 **
  39.      **                                             **
  40.      *************************************************

  41.       1. Print a list of source strings
  42.       2. Prints the strings in order in ASCII
  43.       3. Prints strings in increasing length
  44.       4. Prints the string in increasing order of the first word length
  45.       5. Exit

  46. Please enter a number of the potion : 3

  47. dfkjlgoi 3086058 l;fj
  48. aBCDxyz sdkfhpdgj ' 0968023
  49. ADFDFDGFxv ffk;fjljj 2058-5 2-=3r0-009 Vvvldkjl;jfidflkjg


  50.      *************************************************
  51.      **                                             **
  52.      **                   User Menu                 **
  53.      **                                             **
  54.      *************************************************

  55.       1. Print a list of source strings
  56.       2. Prints the strings in order in ASCII
  57.       3. Prints strings in increasing length
  58.       4. Prints the string in increasing order of the first word length
  59.       5. Exit

  60. Please enter a number of the potion : 4

  61. aBCDxyz sdkfhpdgj ' 0968023
  62. dfkjlgoi 3086058 l;fj
  63. ADFDFDGFxv ffk;fjljj 2058-5 2-=3r0-009 Vvvldkjl;jfidflkjg


  64.      *************************************************
  65.      **                                             **
  66.      **                   User Menu                 **
  67.      **                                             **
  68.      *************************************************

  69.       1. Print a list of source strings
  70.       2. Prints the strings in order in ASCII
  71.       3. Prints strings in increasing length
  72.       4. Prints the string in increasing order of the first word length
  73.       5. Exit

  74. Please enter a number of the potion : 5


  75. D:\[00.Exerciese.2022]\C>
复制代码

题目

题目

最佳答案

查看完整内容

楼主,你认为这个代码它简单吗? 编译、运行实况:
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-10-14 00:51:47 | 显示全部楼层    本楼为最佳答案   
本帖最后由 jackz007 于 2022-10-14 17:11 编辑

        楼主,你认为这个代码它简单吗?
  1. #include <stdio.h>
  2. #include <string.h>

  3. #define LIM 10
  4. #define STLEN 256

  5. int menu(void)
  6. {
  7.         int m                                                                                                              ;
  8.         printf("     *************************************************\n")                                                 ;
  9.         printf("     **                                             **\n")                                                 ;
  10.         printf("     **                   User Menu                 **\n")                                                 ;
  11.         printf("     **                                             **\n")                                                 ;
  12.         printf("     *************************************************\n\n")                                               ;
  13.         printf("      1. Print a list of source strings \n")                                                               ;
  14.         printf("      2. Prints the strings in order in ASCII\n")                                                          ;
  15.         printf("      3. Prints strings in increasing length\n")                                                           ;
  16.         printf("      4. Prints the string in increasing order of the first word length\n")                                ;
  17.         printf("      5. Exit\n\n")                                                                                        ;
  18.         printf("Please enter a number of the potion : ")                                                                   ;
  19.         for(m = 0 ; m < 1 || m > 5 ;) scanf("%d" , & m)                                                                    ;
  20.         printf("\n")                                                                                                       ;
  21.         return m                                                                                                           ;
  22. }

  23. void operate(char strings[][STLEN], int num)
  24. {
  25.         int d[num] , e[num] , i , j , k , m                                                                                ;
  26.         for(;;) {
  27.                 m = menu()                                                                                                 ;
  28.                 if(m > 0 && m < 5) {
  29.                         for(i = 0 ; i < num ; i ++) d[i] = e[i] = i                                                        ;
  30.                         if (m == 3) {
  31.                                 for(i = 0 ; i < num ; i ++) for(e[i] = j = 0 ; strings[i][j] ; j ++) e[i] ++               ;  // e[i] 保存 strings[i] 的长度
  32.                         } else if(m == 4) {
  33.                                 for(i = 0 ; i < num ; i ++) {
  34.                                         for(j = 0 ; strings[i][j] && strings[i][j] == ' ' ; j ++)                          ;
  35.                                         for(k = j ; strings[i][k] && strings[i][k] != ' ' ; k ++)                          ;
  36.                                         e[i] = k - j                                                                       ;  // e[i] 保存 strings[i] 中第一个 word 的长度
  37.                                 }
  38.                         }
  39.                         if(m > 1 && m < 5) {                                                                                  // 只有功能 2 ~ 4 才需要调整 d 中的元素
  40.                                 for(i = 0 ; i < num - 1 ; i ++) {
  41.                                         for(j = i + 1 ; j < num ; j ++) {
  42.                                                 if(m == 2 && strcmp(strings[d[i]] , strings[d[j]]) > 0 || e[d[i]] > e[d[j]]) { // 排序,m = 2 通过 strcmp() 比较字符串,m = 3、4 比较的都是 e
  43.                                                         k = d[i]                                                           ;
  44.                                                         d[i] = d[j]                                                        ;
  45.                                                         d[j] = k                                                           ;
  46.                                                 }
  47.                                         }
  48.                                 }
  49.                         }
  50.                         for(i = 0 ; i < num ; i ++) printf("%s\n" , strings[d[i]])                                         ;
  51.                         printf("\n\n")                                                                                     ;
  52.                 } else {
  53.                         break                                                                                              ;
  54.                 }
  55.         }
  56. }

  57. int main(void)
  58. {
  59.         int i                                                                                                              ;
  60.         char strings[LIM][STLEN]                                                                                           ;
  61.         printf("Please enter some strings , not more than %d.\n" ,  LIM)                                                   ;
  62.         for(i = 0 ; i < LIM && (gets(strings[i])) ; i ++)                                                                  ;
  63.         operate(strings , i)                                                                                               ;
  64. }
复制代码

        编译、运行实况:
  1. D:\[00.Exerciese.2022]\C>g++ -o x x.c

  2. D:\[00.Exerciese.2022]\C>X
  3. Please enter some strings , not more than 10.
  4. aBCDxyz sdkfhpdgj ' 0968023
  5. ADFDFDGFxv ffk;fjljj 2058-5 2-=3r0-009 Vvvldkjl;jfidflkjg
  6. dfkjlgoi 3086058 l;fj
  7. ^Z
  8.      *************************************************
  9.      **                                             **
  10.      **                   User Menu                 **
  11.      **                                             **
  12.      *************************************************

  13.       1. Print a list of source strings
  14.       2. Prints the strings in order in ASCII
  15.       3. Prints strings in increasing length
  16.       4. Prints the string in increasing order of the first word length
  17.       5. Exit

  18. Please enter a number of the potion : 1

  19. aBCDxyz sdkfhpdgj ' 0968023
  20. ADFDFDGFxv ffk;fjljj 2058-5 2-=3r0-009 Vvvldkjl;jfidflkjg
  21. dfkjlgoi 3086058 l;fj


  22.      *************************************************
  23.      **                                             **
  24.      **                   User Menu                 **
  25.      **                                             **
  26.      *************************************************

  27.       1. Print a list of source strings
  28.       2. Prints the strings in order in ASCII
  29.       3. Prints strings in increasing length
  30.       4. Prints the string in increasing order of the first word length
  31.       5. Exit

  32. Please enter a number of the potion : 2

  33. ADFDFDGFxv ffk;fjljj 2058-5 2-=3r0-009 Vvvldkjl;jfidflkjg
  34. aBCDxyz sdkfhpdgj ' 0968023
  35. dfkjlgoi 3086058 l;fj


  36.      *************************************************
  37.      **                                             **
  38.      **                   User Menu                 **
  39.      **                                             **
  40.      *************************************************

  41.       1. Print a list of source strings
  42.       2. Prints the strings in order in ASCII
  43.       3. Prints strings in increasing length
  44.       4. Prints the string in increasing order of the first word length
  45.       5. Exit

  46. Please enter a number of the potion : 3

  47. dfkjlgoi 3086058 l;fj
  48. aBCDxyz sdkfhpdgj ' 0968023
  49. ADFDFDGFxv ffk;fjljj 2058-5 2-=3r0-009 Vvvldkjl;jfidflkjg


  50.      *************************************************
  51.      **                                             **
  52.      **                   User Menu                 **
  53.      **                                             **
  54.      *************************************************

  55.       1. Print a list of source strings
  56.       2. Prints the strings in order in ASCII
  57.       3. Prints strings in increasing length
  58.       4. Prints the string in increasing order of the first word length
  59.       5. Exit

  60. Please enter a number of the potion : 4

  61. aBCDxyz sdkfhpdgj ' 0968023
  62. dfkjlgoi 3086058 l;fj
  63. ADFDFDGFxv ffk;fjljj 2058-5 2-=3r0-009 Vvvldkjl;jfidflkjg


  64.      *************************************************
  65.      **                                             **
  66.      **                   User Menu                 **
  67.      **                                             **
  68.      *************************************************

  69.       1. Print a list of source strings
  70.       2. Prints the strings in order in ASCII
  71.       3. Prints strings in increasing length
  72.       4. Prints the string in increasing order of the first word length
  73.       5. Exit

  74. Please enter a number of the potion : 5


  75. D:\[00.Exerciese.2022]\C>
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-10-14 00:59:31 | 显示全部楼层
有什么问题?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-10-14 01:08:41 | 显示全部楼层
给一下
输入
正确的输出
现在这个程序不正确的输出
如果这个不正确   不明显,那就指出正确和不正确之间的差别
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2022-10-14 09:16:03 | 显示全部楼层
人造人 发表于 2022-10-14 01:08
给一下
输入
正确的输出

已经改好了,下面代码可以正确输出,但如果我要复用prt_strings()这个函数用于所有选项的输出,该怎么改呢?
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define LIM 2
  4. #define STLEN 100
  5. #define EXIT 5
  6. #define STARS "********************************************************************"

  7. int usr_input(char * strings[]);
  8. int menu();
  9. void prt_strings(char strings[][STLEN], int num);
  10. void a_ord(char * strings[], int num);
  11. void len_ord(char * strings[], int num);
  12. void fist_word_len_ord(char * strings[], int num);
  13. char * s_gets(char * Buffer, int maxCount);
  14. int main(void)
  15. {
  16.     int choose, num;
  17.     char usr_strings[LIM + 1][STLEN];
  18.     char *strings[LIM + 1];
  19.     for (int i = 0; i < LIM; i++)
  20.     {
  21.         strings[i] = usr_strings[i];
  22.     }
  23.     num = usr_input(strings);
  24.     while ((choose = menu()) != EXIT)
  25.     {
  26.         switch (choose)
  27.         {
  28.             case 1:
  29.                 prt_strings(usr_strings, num);
  30.                 break;
  31.             case 2:
  32.                 a_ord(strings, num);
  33.                 break;
  34.             case 3:
  35.                 len_ord(strings, num);
  36.                 break;
  37.             case 4:
  38.                 fist_word_len_ord(strings, num);
  39.             default:
  40.                 ;
  41.         }
  42.     }
  43.     return 0;
  44. }

  45. int menu()
  46. {
  47.     puts(STARS);
  48.     int choose;
  49.     puts("1)Print a list of source strings        2)Prints the strings in order in ASCII");
  50.     puts("3)Prints strings in increasing length   4)Prints the string in increasing order of the first word length");
  51.     puts("5)Exit");
  52.     while ((scanf("%d", &choose)) != 1 && choose > 0 && choose < 5)
  53.     {
  54.         puts("Please enter a number of the potion");
  55.     }
  56.     return choose;
  57. }

  58. int usr_input(char * strings[])
  59. {
  60.     puts(STARS);
  61.     int ct = 0;
  62.     printf("Please enter some strings,not more than %d.\n", LIM);
  63.     while (s_gets(strings[ct], STLEN))
  64.     {
  65.         ct++;
  66.         if (ct >= LIM)
  67.             break;
  68.     }
  69.     puts("Entry is complete.");
  70.     return ct;
  71. }

  72. void prt_strings(char strings[][STLEN], int num)
  73. {

  74.     puts(STARS);
  75.     for (int i = 0; i < num; i++)
  76.     {
  77.         puts(strings[i]);
  78.     }
  79. }

  80. void a_ord(char * strings[], int num)
  81. {
  82.     puts(STARS);
  83.     char * tmp;
  84.     for (int i = 0; i < num - 1; i++)
  85.     {
  86.         for (int j = i+1; j < num; j++)
  87.         {
  88.             if (strcmp(strings[i], strings[j]) > 0)
  89.             {
  90.                 tmp = strings[i];
  91.                 strings[i] = strings[j];
  92.                 strings[j] = tmp;
  93.             }
  94.         }
  95.     }
  96.     for (int i = 0; i < num; i++) {
  97.         puts(strings[i]);
  98.     }
  99. }

  100. void len_ord(char * strings[], int num)
  101. {
  102.     char * tmp;
  103.     for (int i = 0; i < num - 1; i++)
  104.     {
  105.         for (int j = i+1; j < num; j++)
  106.         {
  107.             if (strlen(strings[i]) > strlen(strings[j]))
  108.             {
  109.                 tmp = strings[i];
  110.                 strings[i] = strings[j];
  111.                 strings[j] = tmp;
  112.             }
  113.         }
  114.     }
  115.     for (int i = 0; i < num; i++) {
  116.         puts(strings[i]);
  117.     }
  118. }

  119. void fist_word_len_ord(char * strings[], int num)
  120. {
  121.     char * tmp;
  122.     for (int i = 0; i < num - 1; i++)
  123.     {
  124.         for (int j = i + 1; j < num; j++) {
  125.             if ((strchr(strings[i], ' ') - strings[i]) > (strchr(strings[j], ' ') - strings[j]))
  126.             {
  127.                 tmp = strings[i];
  128.                 strings[i] = strings[j];
  129.                 strings[j] = tmp;
  130.             }
  131.         }
  132.     }
  133.     for (int i = 0; i < num; i++) {
  134.         puts(strings[i]);
  135.     }
  136. }


  137. char * s_gets(char Buffer[], int maxCount){
  138.     char * ret_value;
  139.     int i = 0;
  140.     ret_value = fgets(Buffer, maxCount, stdin);
  141.     if (ret_value){
  142.         //替换'\n'为'\0'
  143.         while (Buffer[i] != '\n' && Buffer[i] != '\0') {
  144.             i++;
  145.         }
  146.         if (Buffer[i] == '\n')
  147.             Buffer[i] = '\0';
  148.         else{
  149.             while (getchar() != '\n');
  150.         }
  151.     }
  152.     return ret_value;
  153. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-10-14 11:25:00 | 显示全部楼层
给一下输入/输出
像这样
https://fishc.com.cn/thread-218849-1-3.html
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-10-14 11:26:21 | 显示全部楼层
你这程序需要输入什么?
你期望它输出什么?
这个程序现在输出了什么?
和你期望的输出有什么不同?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2022-10-14 16:41:02 | 显示全部楼层
jackz007 发表于 2022-10-14 14:46
楼主,你认为这个代码它简单吗?

        编译、运行实况:

这就是强者的世界吗。。
但没注释看得头晕,不好学习,能麻烦给个注释嘛。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2022-10-14 16:46:40 | 显示全部楼层
jackz007 发表于 2022-10-14 14:46
楼主,你认为这个代码它简单吗?

        编译、运行实况:

你的意思是用数组来储存字符串的输出顺序吗?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-10-14 16:49:46 | 显示全部楼层
本帖最后由 jackz007 于 2022-10-14 16:52 编辑
须弥芥子 发表于 2022-10-14 16:46
你的意思是用数组来储存字符串的输出顺序吗?


        是的,我用数组 d 来作为 strings 排序时的索引,这样,根据排序结果,只需要调整 d 的元素,就可以在不动 strings 的情况下,达到实现各种依序输出各个字符串的目的。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-10-14 17:13:08 | 显示全部楼层
须弥芥子 发表于 2022-10-14 16:41
这就是强者的世界吗。。
但没注释看得头晕,不好学习,能麻烦给个注释嘛。

         注释来了,7 楼的代码已经更新。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2022-10-14 17:35:25 | 显示全部楼层
jackz007 发表于 2022-10-14 17:13
注释来了,7 楼的代码已经更新。

谢啦~
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-23 11:16

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表