473,386 Members | 1,647 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,386 software developers and data experts.

C/C++ Program for removing the multiple occurences of a words in a string

Hi All,

I need to have a function that should remove the multiple occurrences of all substrings present in a string.
That is the function will be having an input like this:-

char* data=NULL;
/* memory allocation for data and then initializing the data*/
data = {"abc","xyz","abc",sss"};

/*now function call */

data = {"abc","xyz",sss"};


Can anybody help me in this regard ASAP. Code or Algoritham ; anything or any idea.

Thanks a lot,

Raj Kumar Arora
Oct 29 '07 #1
4 2015
Banfa
9,065 Expert Mod 8TB
use C++

put strings in a list

have the function take the strings out of the list and put them in a set. Because of the nature of a set you will not be able to create duplicates.

Then re-create the list from the members of the set.
Oct 29 '07 #2
use C++

put strings in a list

have the function take the strings out of the list and put them in a set. Because of the nature of a set you will not be able to create duplicates.

Then re-create the list from the members of the set.

Thanks Banfa for ur reply, Can u pls help me by explaining it in a little bit detail
because i dont know programming sets. So how programming in set will remove redundancies ; I could not understand this.
Oct 29 '07 #3
Banfa
9,065 Expert Mod 8TB
In a set the data is the key and the key must be unique. If you try to add an entry that already exists it will fail.

By transfering all the entries from a list to a set the duplicate entries will fail on insert leaving a set of unique items.
Oct 29 '07 #4
In a set the data is the key and the key must be unique. If you try to add an entry that already exists it will fail.

By transfering all the entries from a list to a set the duplicate entries will fail on insert leaving a set of unique items.
Thanks for so quick reply;
I will try it and hopefully solve this,

Regards
Raj Kr Arora
Oct 29 '07 #5

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

Similar topics

4
by: Dominique Deleris | last post by:
Hello, I desperately and urgently need a __working__ function, that will replace all occurences of a substring in a string. Prototype should be : char *str_replace(char *str, const char...
9
by: santosh | last post by:
Hello all, I've put together a small program to count the number of characters and 'words' in a text file. The minimum length of a word, (in terms of no. of characters), as well as word...
7
by: Jim Carlock | last post by:
Looking for suggestions on how to handle bad words that might get passed in through $_GET variables. My first thoughts included using str_replace() to strip out such content, but then one ends...
2
by: RadiationX | last post by:
How does this program work? // fig06_07.c -- COP2220 Example -- 040209 (sjd) // Student poll program #include <stdio.h> #include <stdlib.h> #define RESPONSE_SIZE 40 //...
66
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
20
by: Francine.Neary | last post by:
I am learning C, having fun with strings & pointers at the moment! The following program is my solution to an exercise to take an input, strip the first word, and output the rest. It works fine...
18
by: Neehar | last post by:
Hello For one of the interviews I took recently, I was given an offline programming quiz. In 30 minutes I had to write code in C++ to counts the number of times each unique word appears in a...
11
by: George Sakkis | last post by:
I have a situation where one class can be customized with several orthogonal options. Currently this is implemented with (multiple) inheritance but this leads to combinatorial explosion of...
2
code green
by: code green | last post by:
I am trying to write a simple function that will take a string containing an address line or business name and return it nicely formatted. By this I mean extra spaces removed and words capitalised....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.