Thread: using memcpy?

  1. #1
    Registered User nyekknyakk's Avatar
    Join Date
    Aug 2010
    Posts
    35

    using memcpy?

    hi, everyone!
    i've tried using asking for help about using strtok but i wasn't able to get an answer. i will now try to use memcpy..

    but you can still help me with using strtok:
    compare pointer and integer?

    thanks!
    Last edited by nyekknyakk; 08-20-2010 at 08:57 AM.

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Hello,
    You should have
    Code:
    memcpy(array + loop, cmd_str + i , j);
    since array[loop] is not a pointer, it is the value of the actual element, thus *(array+loop)

    Haven't checked if the logic is correct

    But do not use memcpy for this.

    I am sure you will get a lot "don't use gets()" comments so just go ahead and change it to fgets(). See the forums FAQ or google fgets().

    But in any case, I will show you how to use strtok(). You use it always similar (passing the string on the first call and NULL on the second) usually:
    Code:
    char* tok;
    tok = strtok(cmd_str, " "); //you pass your string and the delimiter, which is space for u
    while(tok != NULL)
    {
        printf("%s\n", tok);       //you print your token, one every line
        tok = strtok(NULL, " "); //you pass NULL now to continue on the rest of the string!
    }
    this is the example used here. It is the basic use.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  2. Memcpy(); Errors...
    By Shamino in forum C++ Programming
    Replies: 4
    Last Post: 03-24-2006, 11:35 AM
  3. memcpy with 128 bit registers
    By grady in forum Linux Programming
    Replies: 2
    Last Post: 01-19-2004, 06:25 AM
  4. Trying to copy buffers using memcpy in C under UNIX
    By Meeper in forum C Programming
    Replies: 3
    Last Post: 07-26-2003, 08:51 AM
  5. memcpy
    By doubleanti in forum C++ Programming
    Replies: 10
    Last Post: 02-28-2002, 04:44 PM