I would like to convert the following program to run on a linux system for my school assignment. I am struggling very hard because the linux computer labs are shutdown due to covid. So, I coded my homework on my windows computer. I had access today and it did not run due to multiple errors. What can I do to convert my code to make it linux compatible?
#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")
will generally not work on Linux. It is a built-in command of Windows'CMD.EXE
, which is what runs the "strings" you pass tosystem()
on Windows. On Linux it would (for the sake of argument) be a "bourne-shell", so trysystem("clear")
instead. YMMV.