【发布时间】:2021-06-09 04:34:54
【问题描述】:
我想将以下程序转换为在 linux 系统上运行以完成我的学校作业。我正在努力奋斗,因为 linux 计算机实验室由于 covid 而关闭。所以,我在我的 Windows 电脑上编写了我的作业。我今天可以访问,但由于多个错误而无法运行。我可以做些什么来转换我的代码以使其与 linux 兼容?
#include <stdio.h>
#include <string.h>
char ch;
#define NUMROWS 6
#define NUMCOLS 6
int i, j;
char str1[42] = {'S', '#', '#', '#', '#', '#', '\n', '.', '.', '.', '.', '.', '#', '\n', '#', '.', '#', '#', '#', '#', '\n', '#', '.', '#', '#', '#', '#', '\n', '.', '.', '.', '#', '.', 'G', '\n', '#', '#', '.','.','.','#','\n'};
main()
{
char response[10];
char response2[10];
char yes;
char no;
char ready;
char notready;
printf("Do you want to play the maze game? yes|no : \n");
scanf("%s", &response);
if (!strcmp(response, "yes"))
{
printf("\n");
printf("Game will begin!");
printf("\n");
printf("\n");
printf("Maze Board Example: \n");
printf("S##### \n");
printf(".....# \n");
printf("#.#### \n");
printf("#.#### \n");
printf("...#.G \n");
printf("##...# \n");
printf("\n");
printf("Intstructions:");
printf("Are you ready to play? ready|no \n");
scanf("%s", &response);
if (!strcmp(response, "ready"))
{
printf("playing...");
system("cls");
while(1)
{
mazeGo();
}
}
}
if (!strcmp(response, "no"))
{
printf("\n");
printf("Game will exit");
}
return 0;
}
void mazeGo()
{
str1[0]= '+';
printf("%s", str1);
sleep(1);
system("cls");
str1[7] = '+';
printf("%s", str1);
sleep(1);
system("cls");
str1[8] = '+';
printf("%s", str1);
sleep(1);
system("cls");
str1[9] = '+';
printf("%s", str1);
sleep(1);
system("cls");
str1[10] = '+';
printf("%s", str1);
sleep(1);
system("cls");
str1[11] = '+';
printf("%s", str1);
sleep(1);
system("cls");
str1[15] = '+';
printf("%s", str1);
sleep(1);
system("cls");
str1[22] = '+';
printf("%s", str1);
sleep(1);
system("cls");
str1[28] = '+';
printf("%s", str1);
sleep(1);
system("cls");
str1[29] = '+';
printf("%s", str1);
sleep(1);
system("cls");
str1[30] = '+';
printf("%s", str1);
sleep(1);
system("cls");
str1[37] = '+';
printf("%s", str1);
sleep(1);
system("cls");
str1[38] = '+';
printf("%s", str1);
sleep(1);
system("cls");
str1[39] = '+';
printf("%s", str1);
sleep(1);
system("cls");
str1[32] = '+';
printf("%s", str1);
sleep(1);
system("cls");
str1[33] = '+';
printf("%s", str1);
sleep(1);
system("cls");
printf("\n You win!");
exit(0);
}
【问题讨论】:
-
如果您可以将错误(消息)添加到您的问题中,那将会很有帮助。乍一看,
system("cls")通常无法在 Linux 上运行。它是 Windows 的CMD.EXE的内置命令,它运行您在 Windows 上传递给system()的“字符串”。在 Linux 上,它会(为了争论)是一个“bourne-shell”,所以试试system("clear")。 YMMV。 -
为什么会有这么多不必要的空行?
-
缩进也不一致。让人难以阅读。
-
无关:使用在 Windows 主机中运行的 Linux virtual machine
标签: c linux windows converters