473,385 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

remove substring and character

3
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",substr);
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+strlen(sub));
return;
}
Mar 2 '09 #1
1 4078
gpraghuram
1,275 Expert 1GB
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
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 ...
4
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
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...
0
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...
5
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...
2
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
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...
10
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...
3
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.