-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2-append_text_to_file.c
52 lines (40 loc) · 943 Bytes
/
2-append_text_to_file.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
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
/******************START****************/
/**
* append_text_to_file - function; appends_text at end of the file
*
* @filename:pointer:shows to the name of the file.
*
* @text_content: represent the string to be added at end of_file
*
* Return: filename is NULL -1 when the function fails.
* The user to lack permision on missing file -1
* Elsewhere return 1.
*
* ALX PROJECTS
*/
int append_text_to_file(const char *filename, char *text_content)
{
/**Set Constants**/
const char *f_name = filename;
char *t_c = text_content;
int i;
int j;
int len = 0;
if (f_name == NULL)
return (-1);
if (t_c != NULL)
{
for (len = 0; t_c[len];)
len++;
}
i = open(f_name, O_WRONLY | O_APPEND);
j = write(i, t_c, len);
if (i == -1 || j == -1)
return (-1);
close(i);
return (1);
}
/***************************START**************************/