Monday, 8 December 2014

Program to remove a particular string from existing string part
#include<stdio.h>
#include<string.h>
main()
{
char ch,str1[50],str2[50],*ptr;
printf("enter a string\n");
scanf("%[^\n]s",str1);
printf("enter string2\n");
scanf(" %[^\n]s",str2);
/*for(i=0;str[i];i++)
{
if(str[i]==ch)
strcpy(str+i,str+i+1);
i--;
}*/
ptr=str1;
while(ptr=strstr(ptr,str2))
{
strcpy(ptr,ptr+strlen(str2));
//memset(ptr,'m',strlen(str2));
}
printf("string=%s\n",str1);
}
OutPut:
madan@madan-Lenovo-G570:~/madan$ cc array4.c
madan@madan-Lenovo-G570:~/madan$ ./a.out
enter a string
welcome
enter string2
com
string=wele