Hi guys, being a beginner I have some trouble with pointers. I don't know but something about using pointers is just not getting clear to me.
My assignment requires that from an array of given values, the user inputs a particular integer whose every occurrence with in the array should be deleted and the size of the array should then be reduced respectively. I tried but I am not getting how can I accomplish this with a pointer.
Here is the my code:

// HW5_Bhasin.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
using namespace std;
void Erase(int [], int* ,int* );


int main()
{
	char choice;
	const int max = 5;
	int a[max];
	int itemCount=0, SearchElement=0;


	cout<<"Please select from the following menu."<<endl;
	cout<<"	E(Erase Array Content)\tC(Count Words)\tR(Reverse Words)\tQ(Quit)"<<endl;
	cin>> choice;
	cin.ignore();

	switch(choice)
		case 'E':
		case 'e':
			Erase(a, &itemCount, &SearchElement); 


	return 0;
}

void Erase( int ar[], int *item, int *Search)// this function is suppose to delete every occurrence of the digit input by the user.the item is suppose to keep the count of the array size  search is the item to be deleted.
{
	int digit;

	cout<<"Please enter the number whose all occurrence needs to be deleted."<<endl;
	cin<< digit;

	Search = &digit;

	

	cout<<"Erase this number"<<endl;

	return;
}

Thanks.

thanks for the link. That makes sense but I am confused with using dynamic arrays with my program.
What I mean, in the tutorial for dynamic arrays:
1. it creates a pointer to int, int* a = NULL; but how would I relate this to the array in my function.
2. using n as size variable:
cin>>n;
a = new int[n];
Again how can I use this in my function with the arrays, and the pointer variable in my function *item is suppose to keep the track of the size just like n. But how do I use this variable in the function?

Thanks.

First, I'd like clarification on the assignment and the techniques you're supposed to be using.
- Are you in fact supposed to use dynamically allocated array (using int * )?
- If so, do you have to actually change the size of memory allocation, or just keep track of the fact that you have fewer elements assigned to the array? This second method would also work if you used fixed size arrays ( int [] ) and kept track of number of valid elements.

Well, I should use dynamic arrays(that makes more sense to me). I declared my array as constant just to see if the program works and to be able to compile. I need to replace that with dynamic arrays.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.