Momo wrote:
Can you please give some example?? I beening trying to do that, but i
am having no idea how do i start.
Thx for help.
See Below.
Momo <mo********@gmail.com> wrote:
I have like a string here say: "PROGRAM= sample"
how do i extract this string value so that i can have like
"sample"(notice no space infront of sample) standalone as a char
itself.
any help will be good
You can set a char pointer to the beginning of the string, then
strchr for '=', if successful, increase the pointer, skip spaces
(or all white-space, you can use isspace() for that).
#include <stdio.h>
#include <ctype.h>
#include <string.h>
char *RemoveLeadingWP(char *s);
char *RemoveTrailingWP(char *s);
char *ParseData(char *s);
int main(void)
{
char *result, test[64] = "PROGRAM= A string without leading "
"and trailing Whitespace ";
result = ParseData(test);
if(result)
printf("Parsed string is: \"%s\"\n",result);
return 0;
}
char *RemoveLeadingWP(char *s)
{
char *s1;
for(s1 = s; *s1 != '\0'; s1++)
if(!isspace((unsigned char)*s1)) break;
if(s1 != s) memmove(s,s1,strlen(s1)+1);
return s;
}
char *RemoveTrailingWP(char *s)
{
char *endp;
for(endp = s+strlen(s); endp!=s; endp-- )
if(!isspace((unsigned char)*(endp-1))) break;
*endp = '\0';
return s;
}
char *ParseData(char *s)
{
char *s1;
if((s1 = strrchr(s,'=')) != NULL)
{
RemoveTrailingWP(++s1);
RemoveLeadingWP(s1);
return s1;
}
return NULL;
}
--
Al Bowers
Tampa, Fl USA
mailto:
xa******@myrapidsys.com (remove the x to send email)
http://www.geocities.com/abowers822/