This section illustrates you how to get the substring using library function. You can see in the given example, we have used the library function strstr() provided by the header file <string.h>. The function is declared as:
char *strstr(const char *str1, const char *str2);
In the given code, we have consider will as str2 and the whole string as str1. The function strstr() finds the occurrence of str2 in the str1 and returns the pointer to occurrence of str2 in str1. If no match found, then a null pointer is returned.
Here is the code:
SUB.C
#include <string.h>
|
Output will be displayed as:
SUB.EXE
![]()
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: C get Substring from String
Post your Comment