I'm running into problems with my local debugger on visual studio while trying to learn C++, as soon as it gets to the end of the code it immediately closes and doesn't allow me to close it myself so I can't even see the final bit of output.
As far as I know there are no errors in my code and I tried the getchar()
so that I could enter a character before the debugger closing.
Here's my code just incase there are errors but I don't think there are
#include <iostream>
using namespace std;
int search(char* pchs, int size, char key) {
int count = 0;
for (int i = 0; i < size; i++) {
if (pchs[i] == key)
count++;
}
return count;
}
int main() {
int size = 0;
char key = 0;
cout << "Please enter the size of the array" << endl;
cin >> size;
cout << "Please enter the key (a-z)" << endl;
cin >> key;
char* pchs = new char[size];
if (pchs != NULL) {
for (int i = 0; i < size; i++) {
pchs[i] = 97 + rand() % 26;
cout << pchs[i] << " ";
}
cout << endl;
cout << "No. Occurences: " << search(pchs, size, key) << endl;
}
delete[] pchs;
return 0;
}