-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolumn_str_value.c
43 lines (40 loc) · 1.46 KB
/
column_str_value.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* column_str_value.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sky <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/09/09 22:48:01 by sky #+# #+# */
/* Updated: 2020/09/13 23:56:27 by sky ### ########.fr */
/* */
/* ************************************************************************** */
#include "csvlib.h"
char *column_str_value(char *str, char simv)
{
int i;
int k;
char *line;
i = 0;
if (!str)
return (NULL);
while (str && simv && str[i] && str[i] != simv)
i++;
if (str[i] == simv)
{
k = 0;
i++;
while (str[i + k] && str[i + k] != simv)
k++;
if (str[i + k] == simv)
{
if (!(line = calloc(k + 1, sizeof(char))))
return (NULL);
line[k] = '\0';
while (k--)
line[k] = str[i + k];
return (line);
}
}
return (str);
}