ATTENTION: Newbie question!
I am learning c++ in my university, but it seems that those guys are a bit... outdated. Anyway, I don't want to call them names in here (although I would certainly like to).
The purpose of this exercise is to insert a string from the keyboard and a character, and then to see how many times this character exists inside the string we gave.
They are using borland's TurboC++ (A VERY old tool, and they do not let us to use anything else). This code appears to work correctly on them.
I am learning c++ in my university, but it seems that those guys are a bit... outdated. Anyway, I don't want to call them names in here (although I would certainly like to).
The purpose of this exercise is to insert a string from the keyboard and a character, and then to see how many times this character exists inside the string we gave.
They are using borland's TurboC++ (A VERY old tool, and they do not let us to use anything else). This code appears to work correctly on them.
Code:
#include <iostream.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
void main(){
char *prot1, ch;
int count1 = 0;
gets(prot1);
cin >> ch;
while(*prot1){
if(*prot1==ch){
count1++;
prot1++;
}
}
cout << count1;
}