Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 18 Feb 2008 15:03:54 -0800
From:      Gary Kline <kline@thought.org>
To:        FreeBSD Mailing List <freebsd-questions@FreeBSD.ORG>
Subject:   is there an easier way?
Message-ID:  <20080218230351.GA28000@thought.org>

next in thread | raw e-mail | index | archive | help

	To my fellow C nerds,

	It's been a  great manny years since I wrote this appended
	snippet.  Now I can't remember why (of if ) I need all the
	strcpy() calls.   Is there a simpler, more logical way of 
	printing a bunch of string by snipping off the left-most?

	In short,, can anyone 'splain why strtok needs all this?

	tia,

	gary


-- 
  Gary Kline  kline@thought.org   www.thought.org  Public Service Unix
        http://jottings.thought.org   http://transfinite.thought.org

#include <stdio.h>
#include <string.h>

main()
{
  char *bp, buf[512], *tok, tstr[512];
  static char *delim=" ", s1[256]="abc def ghi jkl mno.";

  bp = strcpy(buf, tstr);  
  strcpy(bp, s1); /* bp filled with writable mem works like this, too */
  while ((tok = strtok(bp, delim)) != NULL)
  {
    bp = NULL; 
    printf("tok = [%s]\n", tok);
  }
}





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080218230351.GA28000>