Thread: issue with strcpy

  1. #1
    Registered User
    Join Date
    Apr 2019

    issue with strcpy

    i have the following call to strcpy
    strcpy(colour_piece_to_take, current_player ? "w" : "b");
    printf("%s\n", colour_piece_to_take);
    i expected it to print out a w to the screen but instead i got -8714

    what is going on??

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    When faced with some weirdness like this, what I'd do is to write a tiny program containing just this along with the necessary declarations, then compile and run it to see what I get. (It's basically the technique described in my signature below.)
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2019
    the issue was im a complete idiot and i typed %d not %s as i didn't cut and paste it didn't transfer across..... it now says w as it should. however i have used your char* p_label trick and all is smiles and roses

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bandwidth issue / network issue with wireless device communication
    By vlrk in forum Networking/Device Communication
    Replies: 0
    Last Post: 07-05-2010, 11:52 PM
  2. Replies: 1
    Last Post: 06-19-2010, 07:42 AM
  3. strcpy() issue
    By philvaira in forum C Programming
    Replies: 4
    Last Post: 03-21-2009, 02:14 PM
  4. strcpy without new
    By sawer in forum C++ Programming
    Replies: 3
    Last Post: 05-05-2007, 04:34 AM
  5. What's up with this strcpy?
    By fanoliv in forum C Programming
    Replies: 7
    Last Post: 06-19-2006, 05:24 PM

Tags for this Thread