> 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/c00/ft_putchar.md).

# ft\_putchar

Objective:

The first exercise in the C00 project is about implementing a simple function called `ft_putchar`. This function will take a single character as input and print it to the screen.

***

### What You Will Learn:

* **Basic C Syntax**: Writing your first function in C, defining function prototypes, and understanding function calls.
* **I/O (Input/Output) Operations**: How to output data to the console.
* **Norminette**: Learning how to follow coding standards and write clean, readable code.
* **Compiling and Testing**: How to compile your C code and test it to make sure it works.

***

### The Task:

You need to write a function `ft_putchar` that prints a character to the screen. It should look like this:

```c
void ft_putchar(char c);
```

#### Example:

If you call `ft_putchar('A');`, it should output:

```css
A
```

#### Step-by-Step Breakdown:

**1. Write the function `ft_putchar`:**

The function `ft_putchar` will take a character `c` as an argument and will output that character to the console using the standard library function `write`.\
The `write` function is defined in `unistd.h` and is used to output data to files or streams. The console is represented by file descriptor `1`.

**2. Function Implementation:**

```c
#include <unistd.h>

void ft_putchar(char c)
{
    write(1, &c, 1);  // Writes the character c to the standard output
}
```

* `write(1, &c, 1)`:
  * `1` refers to the file descriptor for the standard output (the terminal).
  * `&c` is the address of the character `c`. We need to pass a pointer to `write()`, so we use the address operator `&`.
  * `1` is the number of bytes to write. Since we are printing a single character, we specify `1`.

**3. Compiling the Code:**

To compile your C code, you'll use the `gcc` compiler. From the terminal, navigate to your project directory and compile your code using:

```sh
gcc -Wall -Wextra -Werror -o ft_putchar ft_putchar.c
```

* `-Wall -Wextra -Werror` are compiler flags to enable warnings and treat them as errors, helping you write better code.

After compiling, you can run the program like this:

```bash
./ft_putchar
```

However, since this function doesn’t have any direct output (it’s just a single character), you’ll need to test it in a program like:

```c
"ft_putchar.c"

int main() {
    ft_putchar('A');  // This should print 'A'
    return 0;
}
```

**4. Testing:**

After compiling, run the program. If everything is correct, you should see the character `A` printed on the terminal.

<mark style="color:red;">**Before submitting your project, comment out or remove your main function.**</mark><br>


---

# 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/c00/ft_putchar.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.
