my question is:
Write, compile, and run a C++ program to do the following:
1. Declare and initialize a character array named hurray as hurray[ ] = “Hooray for All of Us”. (Such initialization will ensure that the end-of-string escape sequence \0 is included as last entry in the array.)
2. Display the characters in the array using while loop and displaying one character at a time.
Note: You need to declare a pointer variable named hurrayptr, initialize it appropriately, and then use (*hurrayptr++ != ‘\0’)
3. Count the number of elements in the array. Using the count to write a for loop to find the position of letter A in the array hurray.

And here is the code:

// Include Files
#include <iostream> // used for cin, cout
#include <curses.h>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

int counter ( char* );

//Global Variables

int main(void) {

//Declaration Section

char hurray[]="Hooray for all of us";

char *hurrayptr = hurray;

int count=0, position;

*hurrayptr--; // taking pointer back to one more position so that it should display characters properly in the loop.

// NOTE: pointer is current at -1th position, next time in the loop, *hurrayptr++ will bring it to 0th position and it will then only
//print the first character, otherwise it will skip the first character.

count = counter ( *hurrayptr ); // sending the pointer to the function

// counting total characters


// subtract one from returned count because function also counts the NULL '\0' character

cout<<"\n\n Total characters: "<<count;

// showing the positions of 'A'


// setting count to 0 again


for( *hurrayptr = hurray; *hurrayptr!='\0'; *hurrayptr++) {

if(*hurrayptr=='a' || *hurrayptr=='A')

// Every time 'a' is encountered, the position (count) up to that will be printed

cout<<endl<<"'A' is at position: "<<count;



// Count length of array function

int counter( char *hptr ) {

int count=0;

//Specific conditions present in question

while ( *hptr++ != '\0') {




return count;


but it is not running..
nd here is the result.
can you plz tell me the error?