Invalid conversion from int* to int

I keep getting this error!

int *newarr(int, int, int&); //prototype

//[Error] initializing argument 1 of 'int* newarr(int, int, int&)' [-//fpermissive]


arrayptr=newarr(arr,i,ctr); //calling from main ( arrayptr is a pointer )
//[Error] invalid conversion from 'int*' to 'int' [-fpermissive]



//this is the function
1
2
3
4
5
6
7
8
9
10
11
12
13
int *newarr(int arr[],int i,int &ctr)
{
	int *arrayptr=new int[i*2];
	
	for(int j=0;j<i;j++)
		{
			*arrayptr=arr[j];
			arrayptr++;
			ctr++;
		}
		
	return arrayptr;
}


I tried a couple of different things,I don't get whats the problem
Last edited on
what you do in main???
your function expects an array of integers (which is a pointer) to be the first argument.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
int main()
{	
	int arr[5],i=0,j=0,*arrayptr=NULL,ctr=0,*arrayptr1=NULL;
	
	ifstream infile("input.txt");
	if(!infile)								//Error checking if file exists or not
       {   
	   		cout<<"\nERROR!!!\n\nFile does not exist\n\n";
        	system("pause");
       		exit(0);
       }
	
	while(!infile.eof())
		{	
			if(i>5)
				{
					if(ctr==(j*2))
						{
							cout<<"\nExisting array is full, creating a bigger array and moving elements there.\nPlease Wait! "<<endl;
							arrayptr1=morearr(arrayptr,ctr);
							arrayptr1+ctr;		//or 	arrayptr1+(j*2);  
						}
					infile>>*arrayptr1;
					arrayptr1++;
					ctr++;
				}
					
			else if(i==5)
				{
					if(ctr==0)
						{
							cout<<"\nExisting array is full, creating a bigger array and moving elements there.\nPlease Wait! "<<endl;
							arrayptr=newarr(arr,i,ctr);

// this is where i call the newarr function

							arrayptr+i;
						}
					
					infile>>*arrayptr;
					arrayptr++;
					ctr++;
					
					if(ctr==(i*2))
						{
							j=i;
							i++;
						}
					
				}
				
			else if(i<5)
				{
					infile>>arr[i];
					i++;
				}
		
		}

//	for(i=0;i<ctr;i++)
//	cout<<"\n"<<*arrayptr1<<" ";
//	
	divide(arrayptr1,ctr);
	
	infile.close();
	//delete all leaks
	return 0;	
}


i get that this is not the best way to do the work, but I'm mostly concerned about why the error comes!

Even though i solved it by removing the prototype and instead doing the function before the main, but i would still like to know about the error!

thanks!
Your prototype did not match your function definition

int *newarr(int, int, int&); //prototype

int *newarr(int arr[],int i,int &ctr)

your prototype specified that an int would be the first argument, in actual usage you passed an array which is a pointer.
Last edited on
Topic archived. No new replies allowed.