Good day everyone! I have the codes for such a problem where, to create a program that counts how many times the second string appears on the first string. Yes it counts if you put 1 letter only, but if you put 2, it is an error. As an example. If the first string is Harry Partear, and the second string is ar, it must count as 3. Here's the code:
#include <iostream>
#include <conio.h>
using namespace std;
int main ()
{
char first [100], second;
int count;
You have that incorrect behaviour because "second" is declared as a simple char and not a char array.
Also, since you are using C++, why don't you switch to the string data type?
Thank you for the help, it does prompts the user to input the second string. But, after putting the second string, and error appears where the cmd is not working or stopped working. :(
Oh yes I know, but I did not want to write all the code for you! I just wanted to show how you can take two strings in input. Then the part of "counting the repetitions" is up to you...