Thread: strcpy not working correctly?

  1. #1
    Registered User
    Join Date
    Mar 2020
    Posts
    79

    strcpy not working correctly?

    I have the following:

    Code:
        char *mssg, junk, CRC_char[2], sensor = 0xFF, sysID[4] = {SYSTEM_ID}, \
                Send[BUFFER_SIZE] = {[0 ... BUFFER_SIZE-1] = 0xFF}, radioID[4];
    [CODE] P1OUT |= BIT0; strcpy(Send, (const char *)radioID);
    mssg = strncat(mssg, "JR", 2);


    [CODE]

    a breakpoint at line 1 reveals as expected, Send is full '\0'. A breakpoint at line three does not.

    Send contains radioID ...1,2,3,4 BUT also 0xB2 and 0x2F....Can someone explain?
    Thanks
    Last edited by ridgerunnersjw; 12-23-2020 at 02:33 PM.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,596
    Where and how are you allocating memory for mssg?

    A breakpoint at line three does not.
    I don't see any line three, so I don't have a clue.

  3. #3
    Registered User
    Join Date
    Mar 2020
    Posts
    79
    moved to memcpy and all works fine....

  4. #4
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    776
    Do "Send" and "radioID" contain null-terminated strings? If not, string functions (e.g., strcpy) cannot be used on them. (The initializer for "Send" suggests that it's not a string and shouldn't be treated like a string.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 'strcmp and strcpy' Not Working Correctly
    By hufnagel in forum C Programming
    Replies: 6
    Last Post: 04-22-2013, 08:24 AM
  2. fgets not working correctly
    By Charles Seat in forum C Programming
    Replies: 3
    Last Post: 01-24-2012, 12:17 PM
  3. Max/min function not working correctly
    By En-Motion in forum C++ Programming
    Replies: 6
    Last Post: 03-19-2009, 12:28 AM
  4. Pointers are not working correctly
    By adrian_fpd in forum C Programming
    Replies: 8
    Last Post: 11-17-2008, 07:55 PM
  5. constructor not working with strcpy()
    By whackaxe in forum C++ Programming
    Replies: 6
    Last Post: 03-26-2004, 12:15 PM

Tags for this Thread