Click here to Skip to main content
15,888,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include"iostream"
using namespace std;
typedef char* ptr;

void nhapchuoi(ptr &mang, int &n)
{
	cout<<"\nNhap so ky tu: ";
	cin>>n;
	ptr mang = new char[n];        //line error!!!!!!!!!!!!
	for(int i=0;i<n;i++)>
	{
		cout<<"\nNhap ky tu thu "<<i<<" : ";
		cin>>mang[i];
	}
}

void xuatchuoi(ptr mang, int n)
{
	cout<<"\nTa co: ";
	for(int i=0;i<n;i++)>
	{
		cout<<" "<<mang[i];
	}
	cout<<endl;
}

void chen(ptr mang, int n, char kytu)
{
	if(n==0)
	{
		n++;
		ptr mang2 = new char [n];
		mang[0] = kytu;
	}
	else
	{
		n++;
		ptr mang2 = new char[n];
		for(int i=0;i< n-1;i++)
			mang2[i]=mang[i];
		mang2[n-1]=kytu;
		delete[]mang;
		mang=mang2;
		
	}
}

void xetnguyenam(ptr mang, int n, ptr &mang2, int &n2)
{
	cout<<"\nCac nguyen am: ";
	for(int i=0;i<n;i++)>
	{
		if(mang[i]=='a' || mang[i]=='e' || mang[i]=='i' || mang[i]=='o' || mang[i]=='u')
		{
			cout<<" "<<mang[i];
			//chen(mang2,n2,mang[i]);
		}
	}
	  
}

void main()
{
	ptr mang1, mang2;
	int n1,n2;
	nhapchuoi(mang1,n1);
	xuatchuoi(mang1,n1);
	xetnguyenam(mang1,n1,mang2,n2);
	//cout<<"\nCac ky tu nguyen am: ";
	//xuatchuoi(mang2,n2);
	system("pause");
}
Posted
Updated 25-Nov-14 22:55pm
v3
Comments
Aescleal 26-Nov-14 5:24am    
As well as the answer below look at using std::string or std::vector instead of raw character pointers. They're a lot easier to get right at the cost of not a lot of performance.

Additionally remember that main is int main() - void main() is only supported on non-hosted systems. Also get into the habit of initialising all your variables when you declare them, it's bound to save you some grief at some point in your learning or subsequent career.

1 solution

mang is one of the parameters of your function, so you have a variable by that name. You can not declare a second variable with that name...
First declaration:
C++
void nhapchuoi(ptr &mang, int &n)

Second declaration:
C++
ptr mang = new char[n];

If you mean to assign value to that variable than remove the type definition form the beginning of the line:
C++
ptr mang = new char[n];
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900