Hi iam facing the problem while compiling the below program,

program.h ------------headerfile

typedef struct
{
        unsigned char c ;
        unsigned int i ;
        unsigned long l ;
}data_t ;

program.cc ------c++ file

# include <iostream>
# include <malloc.h>
using namespace std ;

# include "ptr.h"

int main()
{
        data_t data[] =
                        {
                                {'A',1,10},
                                {'B',2,11},
                                {'C',3,12}
                        } ;


        data_t *ptr = &data[0] ;

        data_t *ptr = &data[1] ;

     cout<<"ptr->c"<<ptr->c<<"ptr->i"<<ptr->i<<"ptr->l"<<ptr->l ;

return 0 ;
}

i am getting below errors while compiling

error : redclaration of data_t *ptr
error : data_t *ptr previously declared here

so can i allocate memory for ptr before data_t *ptr = &data[1] ; statement, if this is the case please provide me allocating memory for ptr using new operator.

Hi iam facing the problem while compiling the below program,

program.h ------------headerfile

typedef struct
{
unsigned char c ;
unsigned int i ;
unsigned long l ;
}data_t ;


program.cc ------c++ file

# include <iostream>
# include <malloc.h>
using namespace std ;

# include "ptr.h"

int main()
{
data_t data[] =
{
{'A',1,10},
{'B',2,11},
{'C',3,12}
} ;


data_t *ptr = &data[0] ;

data_t *ptr = &data[1] ;

cout<<"ptr->c"<<ptr->c<<"ptr->i"<<ptr->i<<"ptr->l"<<ptr->l ;

return 0 ;
}

i am getting below errors while compiling

error : redclaration of data_t *ptr
error : data_t *ptr previously declared here


so can i allocate memory for ptr before data_t *ptr = &data[1] ; statement, if this is the case please provide me allocating memory for ptr using new operator.

Hi,

Look at your code below, what are you doing ? See the problem ?

data_t *ptr = &data[0] ;

data_t *ptr = &data[1] ;

You are defining a pointer two times ->

data_t *ptr

pleasa give the second one another name may be

data_t *ptr1

hope it help

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.