-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_memset.c
More file actions
55 lines (48 loc) · 943 Bytes
/
ft_memset.c
File metadata and controls
55 lines (48 loc) · 943 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
The purpose of this function is to write 'len' bytes of the value 'c' to a
string. The return value is the first parameter of the function, which is the
void pointer to the string.
*/
#include "libft.h"
void *ft_memset(void *s, int c, size_t n)
{
unsigned char *ptr;
unsigned char char_c;
ptr = (unsigned char *)s;
char_c = (unsigned char) c;
while (n > 0)
{
*ptr = char_c;
ptr++;
n--;
}
return (s);
}
/*
#include <stdio.h>
#include <string.h>
int main(void)
{
char chars[10] = "ABCDEFGHIJ";
char my_chars[10] = "ABCDEFGHIJ";
memset(chars + 5, 'X', 4 * sizeof(char));
ft_memset(my_chars + 5, '9', 4 * sizeof(char));
printf("== TEST: Set a certain block of memory to specific char value ==\n");
printf("memset():\n");
int i = 0;
while (i < 10)
{
printf("%c ", chars[i]);
i++;
}
printf("\nft_memset():\n");
i = 0;
while (i < 10)
{
printf("%c ", my_chars[i]);
i++;
}
printf("\n");
return (0);
}
*/