From nobody@FreeBSD.ORG Tue Oct 26 23:43:56 1999
Return-Path: <nobody@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
Sender: nobody@FreeBSD.ORG
To: freebsd-gnats-submit@freebsd.org
Subject: strsep() 
X-Send-Pr-Version: www-1.0

>Number:         14551
>Category:       misc
>Synopsis:       strsep()
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          doc-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Oct 26 23:50:01 PDT 1999
>Closed-Date:    Mon Nov 1 03:10:49 PST 1999
>Last-Modified:  Mon Nov  1 03:11:30 PST 1999
>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 <string.h>
#include <stdio.h>

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 <string.h>
#include <stdio.h>

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:

From: Kevin Street <street@iname.com>
To: freebsd-gnats-submit@freebsd.org, zh_xf@yahoo.com
Cc:  
Subject: Re: misc/14551: strsep()
Date: Sat, 30 Oct 1999 21:02:07 -0400

 bad program.  Add 
 	inputstring=(char *) malloc(1024); 
 before the 
 	strcpy(inputstring,"...");
 --
 Kevin Street
 street@iname.com
 
State-Changed-From-To: open->closed 
State-Changed-By: sheldonh 
State-Changed-When: Mon Nov 1 03:10:49 PST 1999 
State-Changed-Why:  
OOps. I replied to this one privately and forgot to close the PR when 
the originator mailed me confirmation.  Pilot error. :-) 
>Unformatted:
