Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge: Copying Strings | Common String Operations
Practice
Projects
Quizzes & Challenges
Quiz
Challenges
/
C Strings
Section 3. Chapitre 2
single

single

bookChallenge: Copying Strings

Glissez pour afficher le menu

You have learned about the importance of null-termination, buffer sizes, and the risks of buffer overflow when working with strings in C. Now, you will put these concepts into practice by implementing a function to copy one string into another, ensuring that you do not write past the end of the destination buffer and that the copied string is always properly null-terminated. This challenge will help solidify your understanding of safe string copying techniques.

Tâche

Swipe to start coding

Practice copying strings safely by implementing a function that copies a string from src to dest without overflowing the destination buffer. Your function must ensure that the destination string is always null-terminated.

  • Copy characters from src to dest until either the end of src is reached or dest_size - 1 characters have been copied.
  • Ensure that the destination string is always null-terminated after copying.
  • Do not write more than dest_size bytes to the destination buffer.

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 2
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

some-alt