strcpy and its tests :)))
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -51,3 +51,4 @@ Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
||||
/tests/a
|
||||
/*.org
|
||||
|
||||
28
strcpy.c
Normal file
28
strcpy.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "main.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
/**
|
||||
* _strcpy - strcpy with an n
|
||||
* @dest: the buffer we copying to
|
||||
* @src: the idot we ctrl+c-ed
|
||||
* Return: dest
|
||||
*/
|
||||
char *_strcpy(char *dest, char *src)
|
||||
{
|
||||
int s_idx, i, strlen;
|
||||
char *new_me;
|
||||
|
||||
new_me = malloc(_strlen(dest) + _strlen(src) + 1);
|
||||
strlen = _strlen(src);
|
||||
|
||||
s_idx = -1;
|
||||
while (*(dest + ++s_idx))
|
||||
*(new_me + s_idx) = *(dest + s_idx);
|
||||
|
||||
for (i = 0; i < strlen; i++)
|
||||
*(new_me + s_idx++) = *(src + i);
|
||||
*(new_me + _strlen(new_me)) = '\0';
|
||||
|
||||
|
||||
return (new_me);
|
||||
}
|
||||
17
tests/strcpy.c
Normal file
17
tests/strcpy.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "../main.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
/**
|
||||
* main - why does this not work! I know!
|
||||
* Return: 0...unless?
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
char *str, *str2;
|
||||
|
||||
str = "hello";
|
||||
str2 = " world!\n";
|
||||
str = _strcpy(str, str2);
|
||||
printf("%s", str);
|
||||
return (0);
|
||||
}
|
||||
Reference in New Issue
Block a user