PDA

View Full Version : IDEA: Search And Replace



ygfperson
08-12-2002, 11:22 PM
A program to search a file(s) for a specific piece of text, and replace it with something specified by the user. More configurable the better.

ygfperson
08-12-2002, 11:28 PM
How about a function.. Not like the one you had last time.. But something like...

(from some other site)
You are given two strings (array of chars)- A and B. String A has N cells, and string B has M cells (3<=N,M<=250). You should write a function that will find the longest common sub-string that appears in both- A and B. Common sub-string, is a sequence of chars/ints that appears in the both strings, and from all such equal sub-strings, you should find the one which has greatest length.
For example:
A = 16121353f49ar44
B = 6q6353f0
True answer: 353f
Another example:
A = 1q12e13534a9
B = 67n8f87
True answer: 0 (there is no common sub-strings)

Function prototype:
char *find_substring(char A[], char B[], int N, int M);
or:
char *find_substring(char *A, char *B, int N, int M);

Which one you will use, depends on you. We don't mind no matter which one you will use.

Where:
A is the first array of chars/ints.
B is the second array of chars/ints.
N is the size of A (the number of cells)
M is the size of B (the number of cells)

Your function should return the longest common substring. If there is not such one, then, it should return 0.

Notice: In case there are two sub-strings with the same max length, return the last one