Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want this java code to be converted to C language, please. focus on the word C language. import java.util.*; import java.io.*; public class Puzzle

I want this java code to be converted to C language, please.

focus on the word C language.

import java.util.*;

import java.io.*;

public class Puzzle {

public static void main(String[] args) throws FileNotFoundException ,IOException {

int choice , row , col , k=0 ;

String num ;

String puzzle [][]=load_board(k);

Scanner scan = new Scanner (System.in);

do {

drow_board(load_board (k),k);

System.out.println("1.Insert");

System.out.println("2.Delete");

System.out.println("3.Reset");

System.out.println("4.Check");

System.out.println("5.Exit");

System.out.print("Please select your choice: ");

choice = scan.nextInt();

FileOutputStream outfile = new FileOutputStream ("puzzle.txt");

PrintWriter pw = new PrintWriter(outfile);

switch (choice) {

case 1 :

System.out.print("Enter the row and colum of the cell [0-5]: ");

row= scan.nextInt();

col = scan.nextInt();

if (puzzle[row][col].contains("0")) {

System.out.print("Enter a number [0-9]: ");

num = scan.next();

puzzle[row][col]= num ;

for(int i = 0 ; i

for(int j = 0 ; j

pw.print(puzzle[i][j]+"\t");

}

pw.println();

}

pw.close();

}else {

System.out.println("Error");

System.exit(1);

}

break;

case 2 :

System.out.print("Enter the row and colum of the cell [0-5]: ");

row= scan.nextInt();

col = scan.nextInt();

puzzle[row][col]= "0" ;

for(int i = 0 ; i

for(int j = 0 ; j

pw.print(puzzle[i][j]+"\t");

}

pw.println();

}

pw.close();

break ;

case 3 :

k =-1;

puzzle = load_board(k);

break ;

case 4 :

if (puzzle[0][0].contains("8") && puzzle[0][2].contains("9") && puzzle[0][4].contains("4")&&

puzzle[2][0].contains("6") && puzzle[2][2].contains("7") && puzzle[2][4].contains("3")

&&puzzle[4][0].contains("2") && puzzle[4][2].contains("5") && puzzle[4][4].contains("1"))

System.out.println("Good");

else

System.out.println("Fail");

System.exit(1);

break ;

case 5 :

System.exit(1);

}

k++;

}while(choice != 0);

}

public static String [][] load_board (int k) throws FileNotFoundException {

String [][] puzzle = new String [6][6];

if (k==0 || k==-1) {

FileInputStream infile = new FileInputStream ("data.txt");

Scanner scan = new Scanner(infile);

for (int i = 0 ; i

for(int j = 0 ; j

puzzle[i][j]= scan.next();

}

}

scan.close();

}

else {

FileInputStream infile = new FileInputStream ("puzzle.txt");

Scanner scan = new Scanner(infile);

for (int i = 0 ; i

for(int j = 0 ; j

}

}

scan.close();

}

return puzzle;

}

public static void drow_board (String puzzle [][] , int k) throws FileNotFoundException {

load_board (k);

System.out.println("---------------------------------------------");

for(int i = 0 ; i

for (int j = 0 ; j

if(puzzle[i][j].contains("0"))

System.out.print("| \t");

else if(j==puzzle[i].length-1)

System.out.println("| "+puzzle[i][j]+"|");

else

System.out.print("| "+puzzle[i][j]+"\t");

}

System.out.println("--------------------------------------------");

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions