-
Notifications
You must be signed in to change notification settings - Fork 0
/
char.c
55 lines (50 loc) · 1000 Bytes
/
char.c
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
/*
** char.c for minishell2 in /home/nicolaspolomack/psu/2/PSU_2016_minishell2
**
** Made by Nicolas Polomack
** Login <[email protected]>
**
** Started on Thu Mar 23 10:29:41 2017 Nicolas Polomack
** Last update Fri May 5 06:27:08 2017 Nicolas Polomack
*/
#include <stdlib.h>
void insert_char(char **str, char c)
{
int i;
char *new;
i = -1;
if (*str == NULL)
i = 0;
else
while ((*str)[++i]);
if ((new = malloc(i + 2)) == NULL)
return ;
i = (*str == NULL) ? 0 : -1;
if (*str != NULL)
while ((*str)[++i])
new[i] = (*str)[i];
new[i++] = c;
new[i] = 0;
free(*str);
*str = new;
}
void insert_int(int **str, int c)
{
int i;
int *new;
i = -1;
if (*str == NULL)
i = 0;
else
while ((*str)[++i]);
if ((new = malloc(sizeof(int) * (i + 2))) == NULL)
return ;
i = (*str == NULL) ? 0 : -1;
if (*str != NULL)
while ((*str)[++i])
new[i] = (*str)[i];
new[i++] = c;
new[i] = 0;
free(*str);
*str = new;
}