AlexB <> wrote:
> I've been trying to figure out a way to parse the following:
> 192.168.0.7;username;password;database
> I'm stumped as to how to do that. Should I look for the first occurance
> of the ';', cut out position x through the position of the delimiter by 1,
> move that string to another string and repeat?
What about something like the following? Depends of course a bit on
what you exactly mean by "parsing" etc...
#include <stdio.h>
int main( void )
{
const char *sl = "192.168.0.7;username;password;database";
char ip[ 16 ];
char un[ 100 ];
char pw[ 100 ];
char db[ 100 ];
sscanf( sl, "%15[^;];%99[^;];%99[^;];%99s", ip, un, pw, db );
printf( "%s - %s - %s - %s\n", ip, un, pw, db );
return 0;
}
And, of course, there's the strtok() function, but you need to know
what you are doing if you use it.
Regards, Jens
--
\ Jens Thoms Toerring ___
\__________________________
http://www.toerring.de