Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I don't know the coding for this program. I need help please.
Posted
Updated 27-Oct-12 5:25am
v2

This sounds like your homework, so I'll give you no code! :laugh:

It's not complex, all you have to do is look at it as if it was you doing it, rather than a computer.

You would take the second string (lets call it match) and look for the first occurance in the first string (lets call it source). You would then ignore all the characters in the source up to the beginning of the match you found (plus a bit to make sure you didn't find the same one again) and look for another. And then you would repeat this until teh amount of the source you had left was shorter than the match

So: here is how I would do it:

Create a function, called IsMatch - it returns true if it's a match and false if it isn't.
It takes two parameters, both char*, the first is the source, the second is the match - we will assume that both are null terminated.
Then loop through the strings:
if *source is null, return false.
if *source is not the same as *match, return false.
otherwise, move source and match one one.
if *match is null, return true.
otherwise, go back round the loop.

Then all you have to do is call it in another loop:
each time you go round, call it with source and match. If it returns true, increment your count.
Move source on by one. If *source is null, exit the loop.


All done!
 
Share this answer
 
Comments
ridoy 27-Oct-12 12:49pm    
+5
Have a look at Manpage: strtok and strtok_r[^] that splits strings by delimiters and Manpage: index[^] that gets the occurance of a character in a string, and finally Manpage: strstr[^] to get a substring in a string.
Iterate over the larger string and count the number of loops.
Cheers
Andi
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900