C PROGRAMMING Hi, my question is if I need to create two different functions to
ID: 3576091 • Letter: C
Question
C PROGRAMMING
Hi, my question is if I need to create two different functions to read input for board and then input for drawing commands, and how would they be called on so they continue accepting input until quit. Also, this a correct way to call and save input? Thank you for any help!!!
else if ((strcmp(argv[1], "A") == 0) || (strcmp(argv[1], "a") == 0)) {
printf("entered add");
sscanf(argv[2], "%c", &*command);
sscanf(argv[3], "%d", &*row);
sscanf(argv[4], "%d", &*col);
printf("%c", *command);
im getting a segmentation fault 11 error
1. Command Line Arguments
1. Your program should take as an optional command line parameters the number of rows and
columns to create on the canvas.
This means your program should be able to run as either
1. ./paint.out
2. ./paint.out num_rows num_cols
Either both the rows and columns must be specified or neither should
The number of rows and columns must be integers greater than or equal to 1
If no command line arguments are provided or there is an error in either the number of
command line arguments or their values then a default board of size 10 X 10 should be
created.
2. Commands
1. Your program must be capable of accepting and executing the following commands. The bolded letter inside the parentheses is the letter used to specify the command.
1. (q)uit
1. Cease the execution of the program and free any dynamically created space. 2. (h)elp
1. Display the help information
1. I've given you a function to print this to save you the time copying it
3. (w)rite start_row start_column end_row end_column
1. Draw a line from the starting row and column to the ending row and column
Horizontal lines are drawn using -
Vertical lines are drawn using |
Right diagonal lines are drawn using
Left diagonal lines are drawn using /
If a line you are drawing intersects a portion of a line drawn using a different character than the one you are drawing then a + should be written at the intersecting point
1. For example at the point where a horizontal line and a vertical line intersect a + should be drawn there.
6. If a line you are drawing intersects a portion of a line drawn using the same character as the one you are drawing then you should use continue to use the same character
1. For example a horizontal line drawn over a horizontal line should all be drawn using a -
7. Lines should be able to drawn from either direction
1. For example a horizontal line should be able to drawn from
Left to right to right: w 0 0 0 5
Or right to left: w 0 5 0 0
8. Lines that are 1 cell big should be drawn using -
9. If the line coordinates for the lines entered do not make a straight line you should tell the user and not attempt to draw the line.
4. (e)rase row col
1. Erase the character at row, col reverting it back to a blank space
1. Blank spaces are represented as * in this program
(r)esize num_rows num_cols
Resize the board to be num_rows X num_cols big
The smallest the board can be resized to is 1 X 1
New rows are added to the top of the canvas
New columns are added to the right of the column
New rows/columns are empty
The board can also be resized to be smaller than it currently is
(a)dd [r | c] position
Add a new, empty row/col at the position specified
r stands for row and c for column so
A command to add a new row at position 5 would look like: a r 5
And a command to add a new column at position 7 would look like: a c 7
Valid values for position are between 0 and num_rows/num_cols + 1 based on
whether row or column is specified
If adding a row, rows at and above the position specified are moved up by 1
If adding a new column, columns at and to the right of the position specified are moved 1 to the right
(d)elete [r | c] position
Delete a row column at the specified position
r stands for row and c for column so
A command to delete a row at position 5 would look like: d r 5
And a command to delete a column at position 7 would look like: d c 7
Valid values for position are between 0 and num_rows/num_cols
If deleting a row, rows that are above the row deleted shift down by 1
If deleting a column, columns that are to the right of the row deleted shift to the left by 1
(s)ave file_name
Save the current canvas to the file with the name file_name
How you save the canvas is up to you
(l)oad file_name
Load a canvas from the file with the name file_name
The structure of this file is up to you but the structure should be consistent with files you create from the save command
Explanation / Answer
#include #include /* For exit() function */ int main() { char sentence[1000]; FILE *fptr; fptr = fopen("program.txt", "w"); if(fptr == NULL) { printf("Error!"); exit(1); } printf("Enter a sentence: "); gets(sentence); fprintf(fptr,"%s", sentence); fclose(fptr); return 0; }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.