S
Sidhu
Hoe to relplace the word in sentence? Can any one send program?
Sidhu said:Hoe to relplace the word in sentence? Can any one send program?
Sidhu said:Hoe to relplace the word in sentence? Can any one send program?
Sidhu said:Hoe to relplace the word in sentence? Can any one send program?
Write a function like thisSidhu said:Hoe to relplace the word in sentence? Can any one send program?
Write a function like this
/*
function to replace all instances of a word in a string
Params: out - the output buffer (may not be the same as any input)
original - the original text
search - the sub string to seach for
replacement - the string to replace it with
returns: the number of replacements made
*/
int replace(char *out, char *original, char *search, char *replacement)
#include <stdio.h>
#define F for
#define R return
#define W while
#define RE realloc
#define B break
#define G goto
#define uns unsigned
int repl_m(char* dst, int sdst, char* a,
char* p, int plen, int* next, char *b)
{char *pl, *aa, *ddst;
int con;
// ---------------------
// *p!='\0'
aa=a; ddst=dst; con=0;
W(1){pl=kmn(p, aa, next, plen); // 4+1
if(*pl==0) break; // sz=5
F( ; sdst>0 && aa<pl; --sdst)
*ddst++=*aa++;
F( pl=b; sdst>0 && (*ddst=*pl); --sdst, ++ddst, ++pl);
aa+=plen;
if(sdst<=0) break;
else ++con;
}
F(;sdst>0 && (*ddst++=*aa++); --sdst);
if(sdst<=0) *ddst=0;
// nel caso di errore
// ritorna la lunghezza della nuova linea in negativo
// altrimenti quante volte ha sostituito
R sdst>=0 ? con: (dst-ddst);
.... snip ...Martin said:-snip-
That's too easy... Next time try this:
#define Q for
Write a function like this
/*
function to replace all instances of a word in a string
Params: out - the output buffer (may not be the same as any input)
original - the original text
search - the sub string to seach for
replacement - the string to replace it with
returns: the number of replacements made
*/
Martin said:av wrote:
-snip-
That's too easy...
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.