From: "bowman" Newsgroups: comp.os.msdos.djgpp References: <39CABE68 DOT D5AA584B AT netzero DOT net> <969595461 DOT 718378 AT shelley DOT paradise DOT net DOT nz> <39CCF175 DOT 275438D7 AT netzero DOT net> Subject: Re: Extract a value from a string? Lines: 49 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2014.211 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 Message-ID: Date: Sat, 23 Sep 2000 20:05:30 -0600 NNTP-Posting-Host: 208.26.212.185 X-Trace: newsfeed.slurp.net 969760697 208.26.212.185 (Sat, 23 Sep 2000 20:58:17 CDT) NNTP-Posting-Date: Sat, 23 Sep 2000 20:58:17 CDT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Kenneth A. Strom wrote in message news:39CCF175 DOT 275438D7 AT netzero DOT net... > Would it be better to strstr for = and then extract from the position > of = + 1 into another string and then atoi? Does atoi handle > whitespace? there are several ways to do it. you might want to play with this quick and dirty little example: ------------- snip ------------- #include #include #include int main() { char *ini[] = { "Capture = 1234", "Capture = 0", "Capture = fubar", NULL}; char *ptr; int num; int i; for (i=0; ini[i]; i++) { printf("the string is \"%s\"\n", ini[i]); if (sscanf(ini[i], "%*s = %d", &num) == 1) { printf("sscanf num = %d\n", num); } else { printf("sscanf failed\n"); } ptr = strchr(ini[i], '='); if (ptr) { num = atoi(ptr+1); printf("atoi num = %d\n", num); } printf("\n"); } return 0; }