-
Notifications
You must be signed in to change notification settings - Fork 0
/
writeToConsole.c
55 lines (51 loc) · 1.36 KB
/
writeToConsole.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* Header files goes here */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "main.h"
/**
* writeToConsole - Writes the content of a character
* buffer to the standard output.
*
* @buffer: A pointer to the character buffer whose
* content will be written.
*
* Description:
* This function takes a pointer to a character
* buffer and writes its contents to
* the standard output (console) using the
* `write` system call. If the provided buffer
* is not NULL, the function will write the
* characters in the buffer to the console.
*
* The `write` system call requires three
* parameters: the file descriptor (in this case,
* `STDOUT_FILENO` represents the standard
* output), the buffer containing the data to
* write, and the number of bytes to write
* (determined by the length of the buffer).
*
* If the provided buffer is NULL, the
* function print an error message.
*
* This function is a simple way to
* display the contents of a buffer on the console without
* any formatting or additional content.
*
* Return: None
*/
void writeToConsole(const char *buffer)
{
/* Check for the buffer content */
if (buffer != NULL)
{
/* Write to the std output file "Terminal" */
write(STDOUT_FILENO, buffer, strlen(buffer));
}
else
{
/* Write un error message */
/* printf("Error empty buffer\n"); */
}
}