Thread: Help: makes pointer from integer without a cast

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    15

    Unhappy Help: makes pointer from integer without a cast

    Hello!

    Iam having some problem with my c program again. Hope you can help me.
    I have been working with this for some hours now

    I am trying to make a split function, split a string into an array, I know the number of elements and the delimiter but I am getting some warnings and the program does not work

    This is how it looks
    Code:
    void linetoArray(char* line, unsigned long* arr){
    
      char delims[] = " ";   
      char *result = NULL;
    
      result = strtok( line, &delims[0] );   // problem here
      while( result != NULL ) 
      {   
        printf( "result is \"%s\"\n", result );       
        result = strtok( NULL, &delims[0] );  // problem here
            
      }
    }
    My line looks like this
    char * line = "aaa bbb ccc ddd";
    And my array have 4 places

    I have the warning: assigment makes pointer from integer without a cast
    I have tried sending only delims, and (char*)delims but still the same problem

    Tips?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Did you include "string.h"?

    By the way, you don't need "&delims[0]", you can use "delims".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    15
    Thanks! That solved the problem with the warning, now I have an application error when I run the program... "The instructions at 0x.. referenced memory at 0x.. The memory couldnt not be written"
    help!

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Let's have a guess: You are doing something like:
    Code:
    lineToArray("aaa bbb ccc ddd", ...);
    You can't modify string literals.

    declare a variable like this:
    Code:
    char str[] = "aaa bbb ccc ddd";
    lineToArray(str, ...);
    strtok does modify the first string argument, so you can't use that directly from a string literal.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Sep 2007
    Posts
    15
    Thank you, thank you, and thank you very much!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with error message
    By ddolddolee82 in forum C Programming
    Replies: 10
    Last Post: 05-07-2006, 09:37 PM
  2. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  3. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. Replies: 3
    Last Post: 01-14-2002, 12:13 PM