Date: Tue, 26 Oct 1999 23:43:56 -0700 (PDT) From: zh_xf@yahoo.com To: freebsd-gnats-submit@freebsd.org Subject: misc/14551: strsep() Message-ID: <19991027064356.2BD8E152C2@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
>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 <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: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19991027064356.2BD8E152C2>