C++ strcpy

Posted on 2008-11-06
Last Modified: 2012-05-05
void main()
      char s[100]={'a','b','c','d','e','f','g'};
I thought it should be abcddefg, but it is abcdddfg. Can you explain in detail?
Question by:markdot
    LVL 45

    Expert Comment

    The behavior is undefined
    If copying takes place between objects that overlap, the behavior is undefined.

    Author Comment

    Then, how can we shift the sub-string "defg"  in char s[100]={'a','b','c','d','e','f','g'}?
    LVL 45

    Accepted Solution

    either use memmove or copy them in a loop char by char

    Author Comment

    That is what I need!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
    This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
    The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now