Table of Contents
show
Use of strstr( ) function
#include <stdio.h>
#include<string.h>
int main(){
char s1[100];
char s2[100];
char *ptr;
puts("Enter string1");
gets(s1);
puts("Enter string2");
gets(s2);
ptr = strstr(s1,s2);
if(ptr == NULL){
puts("string not present");
}
else{
printf("string present at %d",ptr-s1);
}
return 0;
}
Output
Enter string1
Hello welcome
Enter string2
wel
string present at 6
Use of strstr( ) function
#include<stdio.h>
#include<string.h>
int main()
{
char s[10] ="123456789";
char ch = 'Z';
puts("string before setting");
puts(s);
strset(s,ch);
puts("string after setting");
puts(s);
return 0;
}
Output
string before setting
123456789
string after setting
ZZZZZZZZZ
Views: 0