-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprefix.c
More file actions
34 lines (26 loc) · 702 Bytes
/
prefix.c
File metadata and controls
34 lines (26 loc) · 702 Bytes
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
#include "main.h"
#include <stdlib.h>
/**
* prefix - returns a malloc'd string prefixed with prefix
* @prefix: string pointer to prefix
* @str: string
*
* Return: A malloc'd string with the prefixed string;
*/
char *prefix(char *prefix, char *str)
{
int pref_len, str_len;
char *prefixed_string = NULL;
if (!prefix || !str)
return (NULL);
pref_len = _strlen(prefix);
str_len = _strlen(str);
prefixed_string = malloc(sizeof(char) * (pref_len + str_len + 1));
if (!prefixed_string)
return (NULL);
/* Copy prefix into prefixed string*/
_strcpy(prefixed_string, prefix);
/* Concatinate string with prefixed string*/
_strcat(prefixed_string, str);
return (prefixed_string);
}