![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| last char from a string | broli | Shell Programming and Scripting | 6 | 12-07-2007 05:02 PM |
| replacing all 4 first upper char of every rec to lowercase ? | Browser_ice | UNIX for Dummies Questions & Answers | 2 | 08-02-2006 09:06 AM |
| string of 7 char length always... | thanuman | UNIX for Dummies Questions & Answers | 3 | 04-12-2005 09:51 AM |
| Compare Char to String | Phobos | High Level Programming | 3 | 04-09-2005 08:01 AM |
| Number of specific char in a string. | gio123bg | Shell Programming and Scripting | 7 | 12-19-2003 11:27 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
replacing char with string
how we can replace char with a string
example char *a="a.s" so finally what i ant to do raplace a with ant and s sree so in my array a i want to store the value as "ant.sree" thank u in advance |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
char *a="a.s"
is constant, you cannot change it. Code:
char dest[24]={0x0};
char src[24]={0x0};
char *p=NULL, *q=NULL;
for(p=src,q=dest; *p; p++)
{
if(*p=='a')
{
strcpy(q,"ant");
q=strchr(q,'\0');
continue;
}
if(*p=='s')
{
strcpy(q,"sree")
q=strchr(q,'\0');
}
else
*q++ = *p;
}
printf("%s\n", dest);
Last edited by reborg; 11-20-2006 at 11:18 AM. Reason: fix typo that stopped the code tags from working |
|||
| Google The UNIX and Linux Forums |