鱼C论坛

 找回密码
 立即注册
查看: 1958|回复: 7

[已解决]哪里错了??

[复制链接]
发表于 2020-3-28 20:24:07 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 孤世星辰 于 2020-3-28 20:25 编辑
  1. test2.c: In function ‘main’:
  2. test2.c:5: error: variable-sized object may not be initialized
  3. test2.c:6: warning: excess elements in array initializer
  4. test2.c:6: warning: (near initialization for ‘a[0]’)
  5. test2.c:6: warning: excess elements in array initializer
  6. test2.c:6: warning: (near initialization for ‘a[0]’)
  7. test2.c:6: warning: excess elements in array initializer
  8. test2.c:6: warning: (near initialization for ‘a[0]’)
  9. test2.c:6: warning: excess elements in array initializer
  10. test2.c:6: warning: (near initialization for ‘a’)
  11. test2.c:7: warning: excess elements in array initializer
  12. test2.c:7: warning: (near initialization for ‘a[0]’)
  13. test2.c:7: warning: excess elements in array initializer
  14. test2.c:7: warning: (near initialization for ‘a[0]’)
  15. test2.c:7: warning: excess elements in array initializer
  16. test2.c:7: warning: (near initialization for ‘a[0]’)
  17. test2.c:7: warning: excess elements in array initializer
  18. test2.c:7: warning: (near initialization for ‘a’)
  19. test2.c:8: error: variable-sized object may not be initialized
  20. test2.c:9: warning: excess elements in array initializer
  21. test2.c:9: warning: (near initialization for ‘b[0]’)
  22. test2.c:9: warning: excess elements in array initializer
  23. test2.c:9: warning: (near initialization for ‘b[0]’)
  24. test2.c:9: warning: excess elements in array initializer
  25. test2.c:9: warning: (near initialization for ‘b’)
  26. test2.c:10: warning: excess elements in array initializer
  27. test2.c:10: warning: (near initialization for ‘b[0]’)
  28. test2.c:10: warning: excess elements in array initializer
  29. test2.c:10: warning: (near initialization for ‘b[0]’)
  30. test2.c:10: warning: excess elements in array initializer
  31. test2.c:10: warning: (near initialization for ‘b’)
  32. test2.c:11: warning: excess elements in array initializer
  33. test2.c:11: warning: (near initialization for ‘b[0]’)
  34. test2.c:11: warning: excess elements in array initializer
  35. test2.c:11: warning: (near initialization for ‘b[0]’)
  36. test2.c:11: warning: excess elements in array initializer
  37. test2.c:11: warning: (near initialization for ‘b’)
  38. test2.c:12: error: variable-sized object may not be initialized
  39. test2.c:12: warning: excess elements in array initializer
  40. test2.c:12: warning: (near initialization for ‘c[0]’)
  41. test2.c:12: warning: excess elements in array initializer
  42. test2.c:12: warning: (near initialization for ‘c’)
  43. test2.c:14: error: expected ‘;’ before ‘)’ token
  44. test2.c:16: error: expected ‘;’ before ‘)’ token
复制代码
  1.   1 #include<stdio.h>
  2.   2 int main()
  3.   3 {
  4.   4         int m=2,p=3,n=2;
  5.   5         int a[m][p]={
  6.   6                 {1,2,3,},
  7.   7                 {4,5,6,}};
  8.   8         int b[p][n]={
  9.   9                 {1,4},
  10. 10                 {2,5},
  11. 11                 {3,6}};
  12. 12         int c[n][m]={0};
  13. 13         int i,j,k,row;
  14. 14         for(i=0,i<m;i++)
  15. 15         {
  16. 16                 for(j=0,j<n;j++)
  17. 17                 {
  18. 18                         for(k=0;k<p;k++)
  19. 19                         {
  20. 20                                 c[i][j]+=a[i][k]*b[k][i];
  21. 21                         }
  22. 22                 }
  23. 23         }
  24. 24         row=m>p?m:p;
  25. 25         for(i=0;i<row;i++)
  26. 26         {
  27. 27                 //打印a
  28. 28                 printf("|  ");
  29. 29                 for(j=0;j<p;j++)
  30. 30                 {
  31. 31                         if(i<m)
  32. 32                         {
  33. 33                                 printf("\b%d ",a[i][j]);
  34. 34                                 printf("|");
  35. 35                         }
  36. 36                         else
  37. 37                         {
  38. 38                                 printf("\b\b\b   ");
  39. 39                         }
  40. 40                 }
  41. 41                 //打印*
  42. 42                 if(i==row/2)
  43. 43                 {
  44. 44                         printf(" * ");
  45. 45                 }
  46. 46                 else
  47. 47                 {
  48. 48                         printf("   ");
  49. 49                 }
  50. 50                 printf("|  ");
  51. 51                 //打印b
  52. 52                 for(j=0;j<n;j++)
  53. 53                 {
  54. 54                         if(i<p)
  55. 55                         {
  56. 56                                 printf("\b%d ",b[i][j]);
  57. 57                         }
  58. 58                         else
  59. 59                         {
  60. 60                                 printf("\b\b\b   ");
  61. 61                         }
  62. 62                 }
  63. 63                 //打印=
  64. 64                 if(i==row/2)
  65. 65                 {
  66. 66                         printf(" = ");
  67. 67                 }
  68. 68                 else
  69. 69                 {
  70. 70                         printf("   ");
  71. 71                 }
  72. 72                 //打印c
  73. 73                 for(j=0;j<n;j++)
  74. 74                 {
  75. 75                         if(i<m)
  76. 76                         {
  77. 77                                 printf("\b%d ",c[i][j]);
  78. 78                         }
  79. 79                         else
  80. 80                         {
  81. 81                                 printf("\b\b\b   ");
  82. 82                         }
  83. 83                 }
  84. 84                 printf("\n");
  85. 85         }
  86. 86 }
复制代码


                               
登录/注册后可看大图
这个是要求,要打印成这个样子
我没定义字符串数组啊,哪里错了??
最佳答案
2020-3-28 20:29:22
变量不能作为数组初始化的维度
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-3-28 20:29:22 | 显示全部楼层    本楼为最佳答案   
变量不能作为数组初始化的维度
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-28 20:45:14 | 显示全部楼层
第五行 数字长度里面只用用常亮不能用变量。 你可以这样做
  1. #define m 3
  2. #define p 2
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2020-3-28 21:02:58 | 显示全部楼层
BngThea 发表于 2020-3-28 20:29
变量不能作为数组初始化的维度

哦哦哦知道了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-28 21:09:44 | 显示全部楼层
BngThea 发表于 2020-3-28 20:29
变量不能作为数组初始化的维度
  1. [gushixingcheng@CentOS-VM Fishc]$ gcc test2.c && ./a.out
  2. test2.c:2:10: warning: missing whitespace after the macro name
  3. test2.c:3:10: warning: missing whitespace after the macro name
  4. test2.c:4:10: warning: missing whitespace after the macro name
  5. test2.c: In function ‘main’:
  6. test2.c:7: error: expected expression before ‘=’ token
  7. test2.c:10: error: expected expression before ‘=’ token
  8. test2.c:14: error: expected expression before ‘=’ token
  9. test2.c:16: error: expected expression before ‘=’ token
  10. test2.c:18: error: expected expression before ‘=’ token
  11. test2.c:20: error: expected expression before ‘=’ token
  12. test2.c:26: error: expected expression before ‘=’ token
  13. test2.c:31: error: expected expression before ‘=’ token
  14. test2.c:54: error: expected expression before ‘=’ token
  15. test2.c:75: error: expected expression before ‘=’ token
复制代码

这个是少了啥表达式??
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-28 21:16:06 | 显示全部楼层
孤世星辰 发表于 2020-3-28 21:09
这个是少了啥表达式??

大括号里最后面多了逗号
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-28 22:27:19 | 显示全部楼层
BngThea 发表于 2020-3-28 21:16
大括号里最后面多了逗号

我看了一下好像没有啊,哪里多了逗号??
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-3-29 09:53:22 | 显示全部楼层
你们叫我春哥吧 发表于 2020-3-28 20:45
第五行 数字长度里面只用用常亮不能用变量。 你可以这样做

  1. [gushixingcheng@CentOS-VM Fishc]$ gcc test2.c && ./a.out
  2. test2.c:2:10: warning: missing whitespace after the macro name
  3. test2.c:3:10: warning: missing whitespace after the macro name
  4. test2.c:4:10: warning: missing whitespace after the macro name
  5. test2.c: In function ‘main’:
  6. test2.c:7: error: expected expression before ‘=’ token
  7. test2.c:10: error: expected expression before ‘=’ token
  8. test2.c:14: error: expected expression before ‘=’ token
  9. test2.c:16: error: expected expression before ‘=’ token
  10. test2.c:18: error: expected expression before ‘=’ token
  11. test2.c:20: error: expected expression before ‘=’ token
  12. test2.c:26: error: expected expression before ‘=’ token
  13. test2.c:31: error: expected expression before ‘=’ token
  14. test2.c:54: error: expected expression before ‘=’ token
  15. test2.c:75: error: expected expression before ‘=’ token
复制代码

这个还是有错,说多了逗号,但是我看了好像没有哇
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-7-6 12:15

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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