Dear Shamnar,
Here is your solution for string problem. I have solved it using Turbo 3.0. Pls. feel free if you need. Just copy the program using notepad using .txt extension and open it in Turbo IDE. Save the Program in Turbo IDE using .C extension. just press CTRL+F9. Input two strings and see the output. str1 is your answer.
[Your problem was: i want a fn which accepts two strings as input and return another string as o/p the o/p should remove second string fron first string.
for example if i/ps are "this" and "is" the o/p should be "th"
pls help me if anyone can.]
ANSWER:
void main() { char str1[25]; char str2[25]; int flag=1; char *ptr1, *ptr2, *temp; clrscr(); printf("Enter two string"); gets(str1); gets(str2); ptr1=str1; ptr2=str2; while(*ptr1 != '\0') { while(*ptr2 != '\0') { if(*ptr1 != *ptr2) ptr2++; else { temp=ptr1; while(*ptr1 != '\0') { if(*ptr1 != *ptr2) { flag=0; break; } ptr1++; ptr2++; } if(flag==1) *temp='\0'; } } ptr1++; ptr2=str2; } printf("\nThe output is\t"); puts(str1); // In str1 the repeated string has been removed. getch(); }
Login