接下来就是问题了。我有一个工作的存储库和两台我编码的计算机。昨天我制作了一个可以在其中一台计算机上运行的程序,然后我在我的存储库中进行了推送。今天我已经下载了这个存储库的内容,但它无法编译。
代码可能取决于我的操作系统(一台机器有 OSX,另一台机器有 Ubuntu)。
谢谢
好的,这是代码:
#include <stdio.h>
enum chess {W, BL, WK, WQ, WP, WR, WH, WB ,BK, BQ, BP, BR, BH, BB};
static const char *chess_string[] = {"O", "X", "WK", "WQ", "WP", "WR", "WH", "WB" ,"BK", "BQ", "BP", "BR", "BH", "BB"};
typedef enum chess chess;
enum chess_letter {A,B,C,D,E,F,G,H};
static const char *chess_letter_string[] = {"A","B","C","D","E","F","G","H"};
typedef enum chess_letter chess_letter;
const int x=8;
const int y=8;
chess table [x][y];
void init_table(int x, int y, chess arr[x][y]){
int i,j;
int c=0;
for(i=0;i<x;i++){
for(j=0;j<y;j++){
if(c==1){
c=0;
arr[i][j]=BL;
}else{
c=1;
arr[i][j]=W;
}
}
if(c==1){
c=0;
}else{
c=1;
}
}
}
void print_table(int x, int y, chess arr[x][y]){
int i;
int j;
printf(" ");
for(i=0;i<x;i++){
printf("%s ",chess_letter_string[i]);
}
printf("\n");
for(i=0;i<x;i++){
printf("%d ",i+1);
for(j=0;j<y;j++){
printf("%s ",chess_string[arr[i][j]]);
}
printf("\n");
}
}
int main(){
init_table(x,y,table);
return 0;
}
它可以在 OSX 中运行,但不能在 Ubuntu 中运行。这是错误:
chess.c:14:7: error: variably modified ‘table’ at file scope
chess table [x][y];
^
chess.c:14:7: error: variably modified ‘table’ at file scope
我使用gcc来编译它。
gcc chess.c -o chess
最佳答案
这只是版本问题。
关于c - c 语言编程取决于操作系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45208754/