All of lore.kernel.org
 help / color / mirror / Atom feed
From: Darren Sessions <dsessions@ionosphere.net>
To: linux-c-programming@vger.kernel.org
Subject: Newbie - Perl Equivalent Split - Seg Faults
Date: Mon, 13 Dec 2004 11:56:25 -0500	[thread overview]
Message-ID: <BDE333E9.1622%dsessions@ionosphere.net> (raw)

Here is a super simple program that (trys) to split a charvar based on a
delimiter. I get no compile errors. If I remove the strtok line, then
split_var returns the string passed to it from main just fine.

I tried changing the char *delim from *delim to delim[50] - same problem.

This is something stupid, and probably super simple. Coming from the Perl
world, I'm trying to write some equivalent string manipulation functions
that I can use throughout my programs to avoid repetition and make the code
cleaner and easier to read.

Thanks in advance,

 - Darren




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

char *split_char(char *string, char *delim) {
  fprintf( stderr, "\tString = %s \n", string);
  fprintf( stderr, "\tDelimiter = %s \n", delim);
  string = strtok(string, delim);
  return string;
}

int main()
{
  char *testvar;
  testvar = split_char("test-hello", "-");
  fprintf( stderr, "\tArray = %s \n", testvar);
  return(0);
}













             reply	other threads:[~2004-12-13 16:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-13 16:56 Darren Sessions [this message]
2004-12-13 17:10 ` Newbie - Perl Equivalent Split - Seg Faults Darren Sessions
2004-12-13 20:21 ` Jan-Benedict Glaw
  -- strict thread matches above, loose matches on Subject: below --
2004-12-13 21:33 Huber, George K RDECOM CERDEC STCD SRI
2004-11-16 21:20 ` J.

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BDE333E9.1622%dsessions@ionosphere.net \
    --to=dsessions@ionosphere.net \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.