-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcg_substr_lb.c
58 lines (35 loc) · 1.14 KB
/
cg_substr_lb.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
56
57
58
/********************************************************************/
/* Function Name: cg_substr_lb
/* Purpose : Extract a string between left boundary and end of string.
/* Input :
/* Output :
/******************************************************************/
char* cg_substr_lb(char* src,char* lbound)
{
char* lpos;
char* newstring;
char* tmpstring;
int start,end,length,i;
int lblength = strlen(lbound);
lpos = (char *)strstr(src, lbound);
// strstr has returned the address. Now calculate * the offset from the beginning of str
start = (int)(lpos - src + 1);
lr_output_message ("The lbound \"%s\" was found at position %d", lbound, start);
start = start + lblength;
length= strlen(src);
if(length<0)
{
lr_output_message("-->Enter string with some characters<--");
return("-1");
}
newstring = (char*)malloc(length+1);
memset(newstring,'\0',length+1);
tmpstring = (char*)strdup(src);
for(i=1;i<start;i++)
{
tmpstring++;
}
strncpy(newstring,tmpstring,length);
lr_output_message("Substring is ::>%s",newstring);
return newstring;
}