Which of the following function is used to find the first occurrence of a string in another string?

By: Prof. Dr. Fazal Rehman | Last updated: February 3, 2024

Question: Which of the following function is used to find the first occurrence of a string in another string?

A strchr ( )

B strrchr ( )

c. strstr ( )

D.strnset ( )

Answer: strstr ( )

 

Function           Prototype Purpose
strstr() ·        char *strstr(const char *haystack

·        const char *needle)

Find the first occurrence of a specified substring needle within a string haystack.
strchr() ·        char *strchr(const char *str, int c) Find the first occurrence of a specified character c in a string str.
strrchr() ·        char *strrchr(const char *str, int c) Find the last occurrence of a specified character c in a string str.
strnset() ·        char *strnset(char *str, int c, size_t n) Set the first n characters of a string str to a specified character c.

 

 

 

All Copyrights Reserved 2025 Reserved by T4Tutorials