You are working on a program that processes user input, and you want to ensure that the input string does not exceed a certain length to prevent buffer overflow. Which string handling function would be appropriate to use?

  • strcpy
  • strncat
  • strncpy
  • strstr
To limit the length of user input and prevent buffer overflow, the strncpy function is appropriate. It allows you to copy a specified number of characters from the input to the destination, ensuring the destination buffer does not overflow. strstr searches for a substring, strncat concatenates strings with a specified limit, and strcpy copies a string without length control.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *