> For the complete documentation index, see [llms.txt](https://42-guide.gitbook.io/42-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://42-guide.gitbook.io/42-guide/piscine-life/rushes/rush00/0.md).

# 0

### **Complete Solution with explanation**

#### **1. Printing a Single Character (`ft_putchar`)**

```c
#include <unistd.h> // Includes write function for output

// Function to print a single character to standard output
void	ft_putchar(char c)
{
	write(1, &c, 1); // Writes character 'c' to standard output
}
```

✅ **Explanation:**

* `write(1, &c, 1);` → Writes the character `c` to the terminal.
* Used throughout the program to print individual characters.

***

#### **2. Printing the First Row (`first_line`)**

```c
// Function to print the first row of the rectangle
void	first_line(int width)
{
	int	i;

	i = 0;
	while (i < width) // Loop through the entire width
	{
		if (i == 0 || i == width - 1) // Print 'o' at the corners
			ft_putchar('o');
		else // Print '-' for the middle part
			ft_putchar('-');
		i++;
	}
	ft_putchar('\n'); // Move to a new line after finishing the row
}
```

✅ **Explanation:**

* Prints the **first row** of the rectangle.
* **First and last characters** are `'o'`.
* **Middle characters** are `'-'`.

***

#### **3. Printing the Last Row (`last_line`)**

```c
// Function to print the last row of the rectangle
void	last_line(int width)
{
	int	i;

	i = 0;
	while (i < width) // Loop through the entire width
	{
		if (i == 0 || i == width - 1) // Print 'o' at the corners
			ft_putchar('o');
		else // Print '-' for the middle part
			ft_putchar('-');
		i++;
	}
	ft_putchar('\n'); // Move to a new line after finishing the row
}
```

✅ **Explanation:**

* **Same logic as `first_line()`**, as the first and last rows are identical.
* Handles different rectangle widths.

***

#### **4. Printing the Middle Rows (`middle_rows`)**

```c
// Function to print the middle rows of the rectangle
void	middle_rows(int width, int height)
{
	int	i, j;

	for (j = 1; j < height - 1; j++) // Loop through each middle row
	{
		for (i = 0; i < width; i++) // Loop through characters in the row
		{
			if (i == 0 || i == width - 1) // Print '|' for left and right borders
				ft_putchar('|');
			else // Print spaces in the middle
				ft_putchar(' ');
		}
		ft_putchar('\n'); // Move to a new line after finishing the row
	}
}
```

✅ **Explanation:**

* Prints the **middle rows** (rows between the first and last row).
* Uses `'|'` for **left and right borders**.
* Uses spaces `' '` for the inside.
* Runs **only if height > 2** (to ensure there is space for a middle section).

***

#### **5. Printing the Full Rectangle (`rush`)**

```c
// Function to print the entire rectangle
void	rush(int width, int height)
{
	if (width <= 0 || height <= 0) // Handle invalid input (negative or zero values)
		return;

	first_line(width); // Print the first row

	if (height > 1) // Print middle rows only if height is greater than 1
		middle_rows(width, height);

	if (height > 1) // Print the last row only if height is greater than 1
		last_line(width);
}
```

✅ **Explanation:**

* **Handles edge cases** (if `width` or `height` is 0 or negative, it does nothing).
* Calls `first_line()`, `middle_rows()`, and `last_line()` in order.

***

#### **6. Main Function (`main`)**

```c
// Main function to test the implementation
int	main(void)
{
	rush(5, 3); // Calls the function with width = 5, height = 3
	return (0);
}
```

✅ **Explanation:**

* Calls `rush(5,3)`, which prints a rectangle **5 characters wide and 3 characters high**.
* You can change values to test different rectangle sizes.

***

### **Summary of Functions and Responsibilities**

| Function Name   | Responsibility                                                    |
| --------------- | ----------------------------------------------------------------- |
| `ft_putchar()`  | Prints a single character                                         |
| `first_line()`  | Prints the first row with 'o' and '-'                             |
| `last_line()`   | Prints the last row (same as `first_line()`)                      |
| `middle_rows()` | Prints the middle rows with '                                     |
| `rush()`        | Calls all the row functions in order and checks for invalid input |
| `main()`        | Starts the program and calls `rush()` with test dimensions        |

***

### **Example Outputs**

#### **Example 1: `rush(5, 3)`**

```
o---o
|   |
o---o
```

#### **Example 2: `rush(1, 1)`**

```
o
```

#### **Example 3: `rush(4, 4)`**

```
o--o
|  |
|  |
o--o
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://42-guide.gitbook.io/42-guide/piscine-life/rushes/rush00/0.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
