Skip to content

Commit 6d15b1c

Browse files
committed
added: libmy.a, main.h
1 parent 41eac75 commit 6d15b1c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+570
-0
lines changed

0x09-static_libraries/0-isupper.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "main.h"
2+
3+
/**
4+
* _isupper - checks for uppercase character.
5+
*
6+
* @c: char to be checked
7+
*
8+
* Return: 1 if @c is uppercase, 0 otherwise
9+
*/
10+
int _isupper(int c)
11+
{
12+
if (c >= 65 && c <= 90)
13+
{
14+
return (1);
15+
}
16+
else
17+
{
18+
return (0);
19+
}
20+
}

0x09-static_libraries/0-isupper.o

1.37 KB
Binary file not shown.

0x09-static_libraries/0-memset.c

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "main.h"
2+
3+
/**
4+
* _memset - fills memory with a constant byte.
5+
*
6+
* @mArea: memory location.
7+
* @buffer: char to be placed in the memory.
8+
* @size: size of buffer to be filled.
9+
*
10+
* Return: pointer to the memory area.
11+
*/
12+
char *_memset(char *mArea, char buffer, unsigned int size)
13+
{
14+
unsigned int index;
15+
16+
for (index = 0; index < size; index++)
17+
{
18+
mArea[index] = buffer;
19+
}
20+
return (mArea);
21+
}

0x09-static_libraries/0-memset.o

1.39 KB
Binary file not shown.

0x09-static_libraries/0-strcat.c

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "main.h"
2+
3+
/**
4+
* _strcat - Concatenates two strings.
5+
*
6+
* @dest: destination var.
7+
* @src: source buffer.
8+
*
9+
* Return: Pointer to the resulting string dest.
10+
*/
11+
char *_strcat(char *dest, char *src)
12+
{
13+
int i1, i2;
14+
15+
i1 = i2 = 0;
16+
while (dest[i1] != '\0')
17+
{
18+
i1++;
19+
}
20+
while (src[i2] != '\0')
21+
{
22+
dest[i1] = src[i2];
23+
i1++;
24+
i2++;
25+
}
26+
dest[i1] = src[i2];
27+
return (dest);
28+
}

0x09-static_libraries/0-strcat.o

1.48 KB
Binary file not shown.

0x09-static_libraries/1-isdigit.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "main.h"
2+
3+
/**
4+
* _isdigit - checks for a digit (0 through 9).
5+
*
6+
* @c: char to be checked
7+
*
8+
* Return: 1 if @c is digit, 0 otherwise
9+
*/
10+
int _isdigit(int c)
11+
{
12+
if (c >= 48 && c <= 57)
13+
{
14+
return (1);
15+
}
16+
else
17+
{
18+
return (0);
19+
}
20+
}

0x09-static_libraries/1-isdigit.o

1.37 KB
Binary file not shown.

0x09-static_libraries/1-memcpy.c

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "main.h"
2+
3+
/**
4+
* _memcpy - copies memory area.
5+
*
6+
* @dest: destination location.
7+
* @src: source location.
8+
* @size: size of buffer to be copied.
9+
*
10+
* Return: pointer to dest.
11+
*/
12+
char *_memcpy(char *dest, char *src, unsigned int size)
13+
{
14+
unsigned int index;
15+
16+
for (index = 0; index < size; index++)
17+
{
18+
dest[index] = src[index];
19+
}
20+
return (dest);
21+
}

0x09-static_libraries/1-memcpy.o

1.4 KB
Binary file not shown.

0x09-static_libraries/1-strncat.c

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "main.h"
2+
3+
/**
4+
* _strncat - Concatenates two strings.
5+
*
6+
* @dest: destination var.
7+
* @src: source buffer.
8+
* @n: num of character to be copied.
9+
*
10+
* Return: Pointer to the resulting string dest.
11+
*/
12+
char *_strncat(char *dest, char *src, int n)
13+
{
14+
int i1, i2;
15+
16+
i1 = i2 = 0;
17+
while (dest[i1] != '\0')
18+
{
19+
i1++;
20+
}
21+
while ((src[i2] != '\0') && (n != i2))
22+
{
23+
dest[i1] = src[i2];
24+
i1++;
25+
i2++;
26+
}
27+
dest[i1] = '\0';
28+
return (dest);
29+
}

0x09-static_libraries/1-strncat.o

1.48 KB
Binary file not shown.

0x09-static_libraries/100-atoi.c

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include <limits.h>
2+
3+
/**
4+
* _isdigit - checks for a digit (0 through 9).
5+
*
6+
* @c: char to be checked
7+
*
8+
* Return: 1 if @c is digit, 0 otherwise
9+
*/
10+
int _isdigit(int c)
11+
{
12+
if (c >= 48 && c <= 57)
13+
{
14+
return (1);
15+
}
16+
else
17+
{
18+
return (0);
19+
}
20+
}
21+
22+
/**
23+
* _atoi - convert a string to an integer.
24+
*
25+
* @s: string to be converted.
26+
*
27+
* Return: the converted number.
28+
*/
29+
int _atoi(char *s)
30+
{
31+
char *ptr;
32+
int size, sign, for_counter, num_size, prev, cur;
33+
34+
size = prev = 0;
35+
sign = 1;
36+
ptr = s;
37+
while (*ptr != '\0')
38+
{
39+
if (*ptr == '-')
40+
{
41+
sign = sign * -1;
42+
ptr = ptr + 1;
43+
continue;
44+
}
45+
46+
if (_isdigit(*ptr))
47+
{
48+
if ((*(ptr + 1) == ' ') || (*(ptr + 1) == '\0'))
49+
{
50+
num_size = size;
51+
for (for_counter = 0; for_counter <= size; for_counter++)
52+
{
53+
cur = *(ptr - num_size) - '0';
54+
if ((prev > (INT_MAX / 10)) || ((INT_MAX - (prev * 10)) < cur))
55+
{
56+
return (sign == 1 ? INT_MAX : INT_MIN);
57+
}
58+
prev = prev * 10 + cur;
59+
num_size--;
60+
}
61+
return (prev * sign);
62+
}
63+
size = size + 1;
64+
}
65+
ptr = ptr + 1;
66+
}
67+
return (0);
68+
}

0x09-static_libraries/100-atoi.o

1.84 KB
Binary file not shown.

0x09-static_libraries/2-strchr.c

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "main.h"
2+
#include <stddef.h>
3+
4+
/**
5+
* _strchr - locates a character in a string.
6+
*
7+
* @string: string to search at.
8+
* @character: character to be searched.
9+
*
10+
* Return: pointer to the first occurence of the character.
11+
*/
12+
char *_strchr(char *string, char character)
13+
{
14+
unsigned int index;
15+
16+
for (index = 0; *(string + index); index++)
17+
{
18+
if (*(string + index) == character)
19+
{
20+
return (string + index);
21+
}
22+
}
23+
if (*(string + index) == character)
24+
{
25+
return (string + index);
26+
}
27+
return (NULL);
28+
}

0x09-static_libraries/2-strchr.o

1.44 KB
Binary file not shown.

0x09-static_libraries/2-strlen.c

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "main.h"
2+
3+
/**
4+
* _strlen - return the length of a string.
5+
*
6+
* @s: string.
7+
*
8+
* Return: length of the string.
9+
*/
10+
int _strlen(char *s)
11+
{
12+
char *ptr;
13+
int size = 0;
14+
15+
ptr = s;
16+
while (*ptr != '\0')
17+
{
18+
size = sizeof(*ptr) + size;
19+
ptr = ptr + 1;
20+
}
21+
return (size);
22+
}

0x09-static_libraries/2-strlen.o

1.38 KB
Binary file not shown.

0x09-static_libraries/2-strncpy.c

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "main.h"
2+
3+
/**
4+
* _strncpy - Copies a string.
5+
*
6+
* @dest: destination var.
7+
* @src: source buffer.
8+
* @n: num of character to be copied.
9+
*
10+
* Return: Pointer to the resulting string dest.
11+
*/
12+
char *_strncpy(char *dest, char *src, int n)
13+
{
14+
int i1, size;
15+
16+
i1 = size = 0;
17+
18+
while (src[size] != '\0')
19+
{
20+
size++;
21+
}
22+
23+
while (n != i1)
24+
{
25+
if (i1 < (size + 1))
26+
{
27+
dest[i1] = src[i1];
28+
}
29+
else
30+
{
31+
dest[i1] = '\0';
32+
}
33+
i1++;
34+
}
35+
return (dest);
36+
}

0x09-static_libraries/2-strncpy.o

1.46 KB
Binary file not shown.

0x09-static_libraries/3-islower.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "main.h"
2+
3+
/**
4+
* _islower - Checks if the char is lowerCase.
5+
*
6+
* @c: the char to be checked.
7+
*
8+
* Return: return (1) if lowerCase (0) otherwise.
9+
*/
10+
int _islower(int c)
11+
{
12+
if (c >= 97 && c <= 122)
13+
{
14+
return (1);
15+
}
16+
else
17+
{
18+
return (0);
19+
}
20+
}

0x09-static_libraries/3-islower.o

1.37 KB
Binary file not shown.

0x09-static_libraries/3-puts.c

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "main.h"
2+
3+
/**
4+
* _puts - print string to stdout.
5+
*
6+
* @str: string to be printed.
7+
*
8+
* Return: Nothing.
9+
*/
10+
void _puts(char *str)
11+
{
12+
char *ptr;
13+
14+
ptr = str;
15+
while (*ptr != '\0')
16+
{
17+
_putchar(*ptr);
18+
ptr = ptr + 1;
19+
}
20+
_putchar('\n');
21+
}

0x09-static_libraries/3-puts.o

1.59 KB
Binary file not shown.

0x09-static_libraries/3-strcmp.c

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "main.h"
2+
3+
/**
4+
* _strcmp - compares two strings.
5+
*
6+
* @s1: string no 1.
7+
* @s2: string no 2.
8+
*
9+
* Return: positive num, zero and negative num.
10+
*/
11+
int _strcmp(char *s1, char *s2)
12+
{
13+
int index = 0;
14+
int value = 0;
15+
16+
while ((*(s1 + index) != '\0') && (*(s2 + index) != '\0'))
17+
{
18+
if (*(s1 + index) != *(s2 + index))
19+
{
20+
value = (*(s1 + index) - *(s2 + index));
21+
break;
22+
}
23+
index++;
24+
}
25+
return (value);
26+
}

0x09-static_libraries/3-strcmp.o

1.48 KB
Binary file not shown.

0x09-static_libraries/3-strspn.c

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "main.h"
2+
3+
/**
4+
* _strspn - gets the length of a prefix substring.
5+
*
6+
* @string: string to be searched at.
7+
* @accept: whitelist characters.
8+
*
9+
* Return: number of bytes in the initial segment of string.
10+
*/
11+
unsigned int _strspn(char *string, char *accept)
12+
{
13+
unsigned int index1, index2;
14+
15+
for (index1 = 0; string[index1]; index1++)
16+
{
17+
for (index2 = 0; accept[index2]; index2++)
18+
{
19+
if (string[index1] == accept[index2])
20+
break;
21+
}
22+
if (string[index1] != accept[index2])
23+
break;
24+
}
25+
return (index1);
26+
}

0x09-static_libraries/3-strspn.o

1.47 KB
Binary file not shown.

0 commit comments

Comments
 (0)