Please the code must be in c program Complete the two functions rotate_right and sudoku_checker according to the specifications given in the associated comments. NOTES: the given starter code includes a display function and a function which reads a board from a file. As given, the main program attempts to read a 9x9 board from an input file given on the command line"
Please the code must be in c program Complete the two functions rotate_right and sudoku_checker according to the specifications given in the associated comments. NOTES: the given starter code includes a display function and a function which reads a board from a file. As given, the main program attempts to read a 9x9 board from an input file given on the command line"
Chapter6: Using Arrays
Section: Chapter Questions
Problem 18RQ
Related questions
Question
Please the code must be in c program
Complete the two functions rotate_right and sudoku_checker according to the specifications given in the associated comments.
NOTES: the given starter code includes a display function and a function which reads a board from a file. As given, the main program attempts to read a 9x9 board from an input file given on the command line"
![```c
#include <stdio.h>
/*
* TODO
* func: rotate_right
* desc: populates 9x9 2D array dest so that it is
* the "90-degree clockwise/right" rotation of
* given
* 9x9 2D array src.
* Imagine turning a square photo 90 degrees
* clockwise.
* Examples:
* given file bl_rot.txt is the 90-degree right
* rotation
* of bl.txt
*/
void rotate_right(int src[9][9], int dest[9][9]) {
}
/**
* TODO
* func: sudoku_checker
* desc: takes a 9x9 matrix of integers and
* "checks" all 27 "entities":
* - 9 rows
* - 9 columns
* - 9 3x3 boxes
* return value: Number of the 27 entities that
* are "ok". Thus if the entire board is
* legal, 27 is returned.
* NOT SIMPLY 0/1
* NOTE: cannot assume that all entries in 2D array
* are
* in the range 1..9
*/
int sudoku_checker(int board[9][9]) {
}
/**
* func: disp_board
* desc: simple function to display a 9x9 sudoku
* board
*/
void disp_board(int board[9][9]) {
printf("\n");
for(i=0; i<9; i++) {
for(j=0; j<9; j++) {
if(j==2 || j==5)
printf("%2d | ", board[i][j]);
else
printf("%2d ", board[i][j]);
}
printf("\n");
if(i==2 || i==5)
printf("----------------------------\n");
}
printf("\n");
}
/*
* func: read_board
* desc: utility function which attempts to open the
* file specified by the string filename and read
* 81 integers from it to populate the 2D array
* board[][].
*
* return value: 1 for success; 0 for failure
*/
int read_board(char *filename, int board[9][9]) {
FILE *fp;
int i, j;](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fac6c0457-7a45-43f2-b38c-64ac65853ed3%2Fa3f8d347-d6b8-477b-b60a-981318f1709c%2Fsa8lagv_processed.jpeg&w=3840&q=75)
Transcribed Image Text:```c
#include <stdio.h>
/*
* TODO
* func: rotate_right
* desc: populates 9x9 2D array dest so that it is
* the "90-degree clockwise/right" rotation of
* given
* 9x9 2D array src.
* Imagine turning a square photo 90 degrees
* clockwise.
* Examples:
* given file bl_rot.txt is the 90-degree right
* rotation
* of bl.txt
*/
void rotate_right(int src[9][9], int dest[9][9]) {
}
/**
* TODO
* func: sudoku_checker
* desc: takes a 9x9 matrix of integers and
* "checks" all 27 "entities":
* - 9 rows
* - 9 columns
* - 9 3x3 boxes
* return value: Number of the 27 entities that
* are "ok". Thus if the entire board is
* legal, 27 is returned.
* NOT SIMPLY 0/1
* NOTE: cannot assume that all entries in 2D array
* are
* in the range 1..9
*/
int sudoku_checker(int board[9][9]) {
}
/**
* func: disp_board
* desc: simple function to display a 9x9 sudoku
* board
*/
void disp_board(int board[9][9]) {
printf("\n");
for(i=0; i<9; i++) {
for(j=0; j<9; j++) {
if(j==2 || j==5)
printf("%2d | ", board[i][j]);
else
printf("%2d ", board[i][j]);
}
printf("\n");
if(i==2 || i==5)
printf("----------------------------\n");
}
printf("\n");
}
/*
* func: read_board
* desc: utility function which attempts to open the
* file specified by the string filename and read
* 81 integers from it to populate the 2D array
* board[][].
*
* return value: 1 for success; 0 for failure
*/
int read_board(char *filename, int board[9][9]) {
FILE *fp;
int i, j;
![```c
// setup to take a file containing a board as a cmd-line
// argument.
//
// e.g. : ./a.out b1.txt
if (argc == 2) {
printf("reading board from file '%s'...\n", argv[1]);
if (!read_board(argv[1], b)) {
printf("reading board failed...goodbye\n");
return 0;
}
else {
printf("success\n");
}
disp_board(b);
}
else {
printf("No filename specified...maybe we had different plans...\n");
}
return 0;
}
#endif
```
### Explanation
This code snippet is written in C and demonstrates how to process command-line input. It specifically looks for a file that contains a "board" and reads it.
- **Command-line Argument Handling**: The program checks if exactly two command-line arguments are passed, which include the program name and the filename containing the board.
- **Reading from File**: If the arguments are correct, it attempts to read the board from the specified file using a function `read_board`.
- **Status Messages**: The program prints status messages to indicate if it was successful or not in reading the board.
- **Display Function**: If successful, it displays the board with the function `disp_board`.
- **Error Handling**: If no filename is specified, it outputs a message indicating that no filename was provided.
- **Return Values**: The program returns 0 in either case, indicating the end of execution.
This code is a simple demonstration of file handling, command-line argument processing, and error checking typical in C programming.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fac6c0457-7a45-43f2-b38c-64ac65853ed3%2Fa3f8d347-d6b8-477b-b60a-981318f1709c%2F7dhjrio_processed.jpeg&w=3840&q=75)
Transcribed Image Text:```c
// setup to take a file containing a board as a cmd-line
// argument.
//
// e.g. : ./a.out b1.txt
if (argc == 2) {
printf("reading board from file '%s'...\n", argv[1]);
if (!read_board(argv[1], b)) {
printf("reading board failed...goodbye\n");
return 0;
}
else {
printf("success\n");
}
disp_board(b);
}
else {
printf("No filename specified...maybe we had different plans...\n");
}
return 0;
}
#endif
```
### Explanation
This code snippet is written in C and demonstrates how to process command-line input. It specifically looks for a file that contains a "board" and reads it.
- **Command-line Argument Handling**: The program checks if exactly two command-line arguments are passed, which include the program name and the filename containing the board.
- **Reading from File**: If the arguments are correct, it attempts to read the board from the specified file using a function `read_board`.
- **Status Messages**: The program prints status messages to indicate if it was successful or not in reading the board.
- **Display Function**: If successful, it displays the board with the function `disp_board`.
- **Error Handling**: If no filename is specified, it outputs a message indicating that no filename was provided.
- **Return Values**: The program returns 0 in either case, indicating the end of execution.
This code is a simple demonstration of file handling, command-line argument processing, and error checking typical in C programming.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 4 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT

Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning

Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning

C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr