Thread: need some noob help

  1. #1
    Registered User
    Join Date
    Dec 2009

    need some noob help

    so I'm working on this project for school, but it's been a while since I've worked in C so I'm having some difficulties... any help would be appreciated.

    char** tokenize (char* str, char* delims, int* arsize){
    	char* strptr;
    	// set the strptr
    	// firstly ignore delims at start of string
    	while(is_delimiter(*strptr, delims)){
    int is_delimiter (char needle, char* haystack){
    		/* if(needle=*haystack)return 1; */
    		if(needle==*haystack++)return 1;
    	return 0;
    so what I wanted to do here is copy the pointer to str into a new char pointer; strptr. Compilation goes fine but on runtime I get a bad pointer exception. Seems like str (which holds a char pointer to the first char in the string) can't be copied to strptr (which is also a char*).

    What am I doing wrong please? I guess it's gotta have something to do with the small difference between a Cstring and a char*, but I can't seem to figure it out...

    thx in advance
    Last edited by klmdb; 01-16-2010 at 11:04 AM.

  2. #2
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Henderson, NV
    I think what you want to do here is Google for strtok()....
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    Quote Originally Posted by klmdb View Post
    Seems like str (which holds a char pointer to the first char in the string) can't be copied to strptr (which is also a char*)
    Something in this statement is false -- if str is a char*, then there will be no problem with strptr=str. Show where str is first declared and the actual call to tokenize.

    There is nothing wrong with the code you posted, presuming that is_delimiter works the way you think it does, etc. If not, strptr could run off the end of str, causing your problem.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User
    Join Date
    Dec 2009
    omg is_delimiter() was indeed the culprit. I feel silly...

    lets see if I can get this code to work now. Might be back with some more questions soon

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Noob to programming need help with a project
    By Wheelsonbus in forum C Programming
    Replies: 6
    Last Post: 02-25-2009, 03:46 AM
  2. Noob Questions...
    By Firemagic in forum C++ Programming
    Replies: 4
    Last Post: 04-19-2006, 03:57 PM
  3. my noob program doesnt work
    By Scarvenger in forum C++ Programming
    Replies: 2
    Last Post: 10-19-2005, 11:40 AM
  4. noob needs help!!!!:(
    By tykenfitz in forum C Programming
    Replies: 1
    Last Post: 07-10-2005, 08:49 AM
  5. simple noob question: HWND, HDC etc.
    By freedik in forum Windows Programming
    Replies: 12
    Last Post: 08-19-2003, 03:59 AM