473,624 Members | 2,534 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

remove substring and character

3 New Member
for this c program, i'd like to remove the substring "cc" and character "=" from input string "aaccbbccdd " the code below can only remove "cc" once, can somebody help me figure out how to remove other "cc" in the string also how to remove multiple character '=' ?

#include <stdio.h>
#include <string.h>


char *Mystrcpy1(char *s, const char *cs);
void func1(char *src, char *sub);

int main(void)
{
char s[32], *substr = "cc";


Mystrcpy1(s,"== aaccbbccdd");
printf("From the string: \"%s\"\n",s) ;
printf("We will attempt to remove substring \"%s\"\n",subst r);
func1(s,substr) ;
printf("Using function Mystrcpy1. The result: \"%s\"\n\n", s);

return 0;
}


char *Mystrcpy1(char *s, const char *cs)
{ /* Copy from beginning of string cs to the end */
char *s1;
const char *cs1;


for(s1 = s,cs1 = cs; '\0' != (*s1 = *cs1); s1++,cs1++) ;
return s;
}



void func1(char *src, char *sub)
{ /* Using function Mystrcpy1 */
char *p;


if ((p=strstr(src, sub)) != NULL)
Mystrcpy1(p,p+s trlen(sub));
return;
}
Mar 2 '09 #1
1 4091
gpraghuram
1,275 Recognized Expert Top Contributor
Hi,
You have to call your replace function till you find a substring in your code that is till strstr returns NULL.
After doing replacement of cc you shuld call your function in the same way to replace =.

Raghu
Mar 2 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
6284
by: carmoda | last post by:
this is a question for someone smarter than me: how would i go about removing just the first character in a column? i.e: if i wanted to remove the 'A' in the ItemSKU column ItemID ItemSKU ItemName 1 A09807969 Red T-Shirt 2 A09807970 Green T-Shirt 3 A09807975 Blue Skirt
4
3009
by: Mikael Petterson | last post by:
Hi, I got some help to go from: bbBusState to BB_BUS_STATE. However I found out :-( that the xml contained attributes like: TxDeviceGroup and that becomes:
1
8099
by: sysindex | last post by:
I am trying to find a way to dynamically retrieve the substring starting point of an nText field. My query looks something like SELECT ID,Substring(DOCTEXT,0,200) from mytable where DOCTEXT like 'claim%'" This query has substring starting point set to 0. Is there a way to determine the starting point based on the first occurrence of the
0
3809
by: Gazi Mahmud | last post by:
I am trying to find a way to dynamically retrieve the substring starting point for an nText field. My query looks something like SELECT ID,Substring(DOCTEXT,0,200) from mytable where DOCTEXT like 'claim%'" This query has substring starting point set to 0. Is there a way to
5
2923
by: btober | last post by:
I can't seem to get right the regular expression for parsing data like these four sample rows (names and addresses changed to ficticious values) from a text-type column: Yolanda Harris, 38, of 40 South Main St., Newtown City, was charged Sunday with breach of peace and interfering with a police officer. Allen K. George, 30, of 88 Beverly Court was charged Saturday with possession of marijuana, third-degree criminal mischief, breach of...
2
2021
by: David Filion | last post by:
Hi, I have a question about substring(), when I run the following query: prepaid=# select substring('15148300', 0, 5); substring ----------- 1514 (1 row)
4
4903
by: Jean-Guy Mouton | last post by:
Hello, I am teaching myself Dom scripting with Javascript. I do not understand how to get a substring. If I have strings in the form: "This is string number 1" How can I put "1" into a variable to use it elsewhere? I thought I could use the function split and create an array but I have different string lengths with a variable number of words... Can you please help me? Thank you.
10
3192
by: Mike Copeland | last post by:
I have data I need to normalize - it's "name" data. For example, I have the following: "Watts, J.C." I wish to (1) parse the "first name" ("J.C.") and adjust it to "JC". Essentially, I want to remove the punctuation characters from the "first name" substring. I've looked at the basic_string in C++, but I can't find the functions that will _remove" character(s) from a value. There are operators that are helpful in finding the position...
3
2582
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
Two part question: 1. Is Regex more efficient than manually comparing values using Substring? 2. I've never created a Regex expression. How would I use regex to do the equivalent of what I have coded using Substrings below? string s = TextBox1.Text.ToUpper(); string ch = s.Substring(0, 1); // read first character if ((ch == "B") || (ch == "C") || (ch == "X")) {
0
8672
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8614
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7153
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6107
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4075
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4167
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2603
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.