I am solving a problem in C where i have to find duplicate words in astring like
char a[]="This is it This";
In above string “This” appears two times so I would like to count it as one.
Can anybody suggest how to achieve this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here is a program that does what you’re asking. It is hard coded for 4 words of a max 99 characters. That can be changed easily; I just fit it around your input. I also used
strcmpandstrcpy. Both of these functions can be implemented on your own (call them mystrcpy and mystrcmp and embed them). I’m not rewriting the string functions for you. I did show how to avoid strtok based on the other answer. I looked them up and they are not complex, but they did not add anything to the program and I didn’t want to reinvent the wheel. Last of all, I just used a simple linear search in thenotInArrayfunction. For a large data set this is not efficient (you would probably use some type of tree or hash).This was compiled under gcc version 4.3.4
The output looks like:
Enjoy.