哪里错了??
本帖最后由 孤世星辰 于 2020-3-28 20:25 编辑test2.c: In function ‘main’:
test2.c:5: error: variable-sized object may not be initialized
test2.c:6: warning: excess elements in array initializer
test2.c:6: warning: (near initialization for ‘a’)
test2.c:6: warning: excess elements in array initializer
test2.c:6: warning: (near initialization for ‘a’)
test2.c:6: warning: excess elements in array initializer
test2.c:6: warning: (near initialization for ‘a’)
test2.c:6: warning: excess elements in array initializer
test2.c:6: warning: (near initialization for ‘a’)
test2.c:7: warning: excess elements in array initializer
test2.c:7: warning: (near initialization for ‘a’)
test2.c:7: warning: excess elements in array initializer
test2.c:7: warning: (near initialization for ‘a’)
test2.c:7: warning: excess elements in array initializer
test2.c:7: warning: (near initialization for ‘a’)
test2.c:7: warning: excess elements in array initializer
test2.c:7: warning: (near initialization for ‘a’)
test2.c:8: error: variable-sized object may not be initialized
test2.c:9: warning: excess elements in array initializer
test2.c:9: warning: (near initialization for ‘b’)
test2.c:9: warning: excess elements in array initializer
test2.c:9: warning: (near initialization for ‘b’)
test2.c:9: warning: excess elements in array initializer
test2.c:9: warning: (near initialization for ‘b’)
test2.c:10: warning: excess elements in array initializer
test2.c:10: warning: (near initialization for ‘b’)
test2.c:10: warning: excess elements in array initializer
test2.c:10: warning: (near initialization for ‘b’)
test2.c:10: warning: excess elements in array initializer
test2.c:10: warning: (near initialization for ‘b’)
test2.c:11: warning: excess elements in array initializer
test2.c:11: warning: (near initialization for ‘b’)
test2.c:11: warning: excess elements in array initializer
test2.c:11: warning: (near initialization for ‘b’)
test2.c:11: warning: excess elements in array initializer
test2.c:11: warning: (near initialization for ‘b’)
test2.c:12: error: variable-sized object may not be initialized
test2.c:12: warning: excess elements in array initializer
test2.c:12: warning: (near initialization for ‘c’)
test2.c:12: warning: excess elements in array initializer
test2.c:12: warning: (near initialization for ‘c’)
test2.c:14: error: expected ‘;’ before ‘)’ token
test2.c:16: error: expected ‘;’ before ‘)’ token
1 #include<stdio.h>
2 int main()
3 {
4 int m=2,p=3,n=2;
5 int a={
6 {1,2,3,},
7 {4,5,6,}};
8 int b={
9 {1,4},
10 {2,5},
11 {3,6}};
12 int c={0};
13 int i,j,k,row;
14 for(i=0,i<m;i++)
15 {
16 for(j=0,j<n;j++)
17 {
18 for(k=0;k<p;k++)
19 {
20 c+=a*b;
21 }
22 }
23 }
24 row=m>p?m:p;
25 for(i=0;i<row;i++)
26 {
27 //打印a
28 printf("|");
29 for(j=0;j<p;j++)
30 {
31 if(i<m)
32 {
33 printf("\b%d ",a);
34 printf("|");
35 }
36 else
37 {
38 printf("\b\b\b ");
39 }
40 }
41 //打印*
42 if(i==row/2)
43 {
44 printf(" * ");
45 }
46 else
47 {
48 printf(" ");
49 }
50 printf("|");
51 //打印b
52 for(j=0;j<n;j++)
53 {
54 if(i<p)
55 {
56 printf("\b%d ",b);
57 }
58 else
59 {
60 printf("\b\b\b ");
61 }
62 }
63 //打印=
64 if(i==row/2)
65 {
66 printf(" = ");
67 }
68 else
69 {
70 printf(" ");
71 }
72 //打印c
73 for(j=0;j<n;j++)
74 {
75 if(i<m)
76 {
77 printf("\b%d ",c);
78 }
79 else
80 {
81 printf("\b\b\b ");
82 }
83 }
84 printf("\n");
85 }
86 }
https://xxx.ilovefishc.com/forum/201604/27/010636hqzxaehdeoxqnmfn.png这个是要求,要打印成这个样子
我没定义字符串数组啊,哪里错了??
变量不能作为数组初始化的维度 第五行 数字长度里面只用用常亮不能用变量。 你可以这样做 #define m 3
#define p 2 BngThea 发表于 2020-3-28 20:29
变量不能作为数组初始化的维度
哦哦哦知道了 BngThea 发表于 2020-3-28 20:29
变量不能作为数组初始化的维度
$ gcc test2.c && ./a.out
test2.c:2:10: warning: missing whitespace after the macro name
test2.c:3:10: warning: missing whitespace after the macro name
test2.c:4:10: warning: missing whitespace after the macro name
test2.c: In function ‘main’:
test2.c:7: error: expected expression before ‘=’ token
test2.c:10: error: expected expression before ‘=’ token
test2.c:14: error: expected expression before ‘=’ token
test2.c:16: error: expected expression before ‘=’ token
test2.c:18: error: expected expression before ‘=’ token
test2.c:20: error: expected expression before ‘=’ token
test2.c:26: error: expected expression before ‘=’ token
test2.c:31: error: expected expression before ‘=’ token
test2.c:54: error: expected expression before ‘=’ token
test2.c:75: error: expected expression before ‘=’ token
这个是少了啥表达式?? 孤世星辰 发表于 2020-3-28 21:09
这个是少了啥表达式??
大括号里最后面多了逗号 BngThea 发表于 2020-3-28 21:16
大括号里最后面多了逗号
我看了一下好像没有啊,哪里多了逗号??
你们叫我春哥吧 发表于 2020-3-28 20:45
第五行 数字长度里面只用用常亮不能用变量。 你可以这样做
$ gcc test2.c && ./a.out
test2.c:2:10: warning: missing whitespace after the macro name
test2.c:3:10: warning: missing whitespace after the macro name
test2.c:4:10: warning: missing whitespace after the macro name
test2.c: In function ‘main’:
test2.c:7: error: expected expression before ‘=’ token
test2.c:10: error: expected expression before ‘=’ token
test2.c:14: error: expected expression before ‘=’ token
test2.c:16: error: expected expression before ‘=’ token
test2.c:18: error: expected expression before ‘=’ token
test2.c:20: error: expected expression before ‘=’ token
test2.c:26: error: expected expression before ‘=’ token
test2.c:31: error: expected expression before ‘=’ token
test2.c:54: error: expected expression before ‘=’ token
test2.c:75: error: expected expression before ‘=’ token
这个还是有错,说多了逗号,但是我看了好像没有哇
页:
[1]