-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "holberton.h" | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
/** | ||
* main - check the code for Holberton School students. | ||
* | ||
* Return: Always 0. | ||
*/ | ||
int main(void) | ||
{ | ||
char *concat; | ||
|
||
concat = string_nconcat("Holberton ", "School !!!", 6); | ||
printf("%s\n", concat); | ||
free(concat); | ||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "holberton.h" | ||
|
||
/** | ||
* _strlen - measures the length of a string. | ||
* Descritpion: measures the string s. | ||
* @s: string to be messured/ | ||
* Return: returns length of s. | ||
*/ | ||
unsigned int _strlen(char *s) | ||
{ | ||
unsigned int count; | ||
|
||
count = 0; | ||
while (s[count] != '\0') | ||
{ | ||
count++; | ||
} | ||
return (count); | ||
} | ||
|
||
/** | ||
* string_nconcat - cats two strings by amount n. | ||
* @s1: string 1. | ||
* @s2: string 2. | ||
* @n: amount to take. | ||
* Return: returns pointer to new string, NULL on fail. | ||
*/ | ||
char *string_nconcat(char *s1, char *s2, unsigned int n) | ||
{ | ||
char *temp; | ||
unsigned int h, i, size; | ||
|
||
if (s1 == NULL) | ||
s1 = ""; | ||
if (s2 == NULL) | ||
s2 = ""; | ||
|
||
if (n > _strlen(s2)) | ||
size = _strlen(s1) + _strlen(s2); | ||
else | ||
size = _strlen(s1) + n; | ||
|
||
temp = malloc((size + 1) * sizeof(char)); | ||
if (temp == NULL) | ||
return (NULL); | ||
|
||
for (h = 0; s1[h] != '\0'; h++) | ||
temp[h] = s1[h]; | ||
for (i = 0; h < size && s2[i] != '\0'; i++, h++) | ||
temp[h] = s2[i]; | ||
|
||
temp[h] = '\0'; | ||
return (temp); | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters