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.
Loading...
Related Quiz
- You need to implement a function that modifies multiple variables of different data types. What concept related to pointers would you use?
-
What is the difference between #include "filename" and #include
in C? - What is the function of the #define preprocessor directive in a C program?
- You are writing a C program where you need to maintain a counter that persists across multiple function calls. Which type of variable would you use?
- The function ________ is used to read formatted input from the standard input.