The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 11-19-2006
Registered User
 

Join Date: Nov 2006
Posts: 52
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
Reply With Quote
Forum Sponsor
  #2  
Old 11-20-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,274
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:31 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0