ok i have to write a function that receives a pointer to a character string and a character. the function should return the number of times the charcter occurred in the string. ok my problem is If i declare a string i can get the program to work say for instance char strg1[]=" My car has a crack in it"; BUT i cant get it to work when i just use char strg1[50]; and if i cin>> enter in my car has a crack. it only reads my????????? y is this
using namespace std;
int main()
{
int count(0);
int charcnt(char *ptr1, char c);
char strg1[50],strg2[]="c";
cout <<"Please enter in your first string up to 50 characters."<<endl<<endl;
cin >> strg1;
cout<< strg1;
char *ptr1(strg1);
while(*ptr1)
{
if(*ptr1 == 'c' )
count++;
ptr1++;
}
cout <<"The Char c appears "<<count<<" times in Strg1."<<endl;