The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 08:02 PM
replacing all 4 first upper char of every rec to lowercase ? Browser_ice UNIX for Dummies Questions & Answers 2 08-02-2006 12:06 PM
string of 7 char length always... thanuman UNIX for Dummies Questions & Answers 3 04-12-2005 12:51 PM
Compare Char to String Phobos High Level Programming 3 04-09-2005 11:01 AM
Number of specific char in a string. gio123bg Shell Programming and Scripting 7 12-19-2003 02:27 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-20-2006
phani_sree phani_sree is offline
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
  #2 (permalink)  
Old 11-20-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
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 02:18 PM.. Reason: fix typo that stopped the code tags from working
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:56 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0