From owner-freebsd-bugs Tue Oct 26 23:50: 4 1999 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 80D3D152C2 for ; Tue, 26 Oct 1999 23:50:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id XAA28455; Tue, 26 Oct 1999 23:50:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: by hub.freebsd.org (Postfix, from userid 32767) id 2BD8E152C2; Tue, 26 Oct 1999 23:43:56 -0700 (PDT) Message-Id: <19991027064356.2BD8E152C2@hub.freebsd.org> Date: Tue, 26 Oct 1999 23:43:56 -0700 (PDT) From: zh_xf@yahoo.com To: freebsd-gnats-submit@freebsd.org X-Send-Pr-Version: www-1.0 Subject: misc/14551: strsep() Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 14551 >Category: misc >Synopsis: strsep() >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: doc-bug >Submitter-Id: current-users >Arrival-Date: Tue Oct 26 23:50:01 PDT 1999 >Closed-Date: >Last-Modified: >Originator: Zhang,xiaofeng >Release: 3.0 maybe >Organization: inforian >Environment: unix >Description: Hi: I am a new user to FreeBSD. When I use the following program,I expected the out put would be; argv=aaa argv=bbbb argv=dd argv=kkkk but actually the output is argv= argv=bbbb argv=dd argv=kkkk I don't where argv[0] was missing. #include #include void main(){ char **ap, *argv[10],*inputstring; //[10] int i; strcpy(inputstring,"aaa\tbbbb\tdd\tkkkk"); for (ap = argv; (*ap = strsep(&inputstring, "\t")) != NULL;) if (**ap != '\0') if (++ap >= &argv[10]) break; for(i=0;i<4;i++) printf("argv=%s\n",argv[i]); } >How-To-Repeat: >Fix: Sorry to use following method to fix the problem #include #include void main(){ char **ap, *argv[10],*inputstring; //[10] char s3[32]; int i; strcpy(inputstring,"aaa\tbbbb\tdd\tkkkk"); i=0; for (ap = argv; (*ap = strsep(&inputstring, "\t")) != NULL;) { if(i==0) strcpy(s3,*ap); i++; if (**ap != '\0') if (++ap >= &argv[10]) break; } strcpy(argv[0],s3); for(i=0;i<4;i++) printf("argv=%s\n",argv[i]); } >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message