Link to home
Start Free TrialLog in
Avatar of dazedandconfused69
dazedandconfused69

asked on

compile error, pointer declaration

I am brand new to pointers and am pretty new to coding in general.  I am going through a pointers tutorial and a suggested exercise is to write a program that copies a specified number of integers from one array to another array. I have many errors when I compile but I will start w/1st and separate them as I have been recommended to do.
#include <stdlib.h>
#include <stdio.h>
int intsA[5] = {9,9,9,9,9};
int intsB[5] = {0,0,0,0,0};
int *pointerA, *pointerB;
pointerA = intsA;

Open in new window


I get the following errors on line 6:

tut_intcopy.c:6: warning: data definition has no type or storage class
tut_intcopy.c:6: error: conflicting types for ‘pointerA’

I cannot figure out why this is happening.  I thought I declared the pointer type with the "int" syntax.  
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

That code  builds just fine for me... the error must be related to something else.
Can you post the actual code please?
Avatar of dazedandconfused69
dazedandconfused69

ASKER

Sorry - here is the entire code (yes, I know I have other errors but splitting up the questions) and the 4 errors associated with the section before main and another function I am including:

errors:


tut_intcopy.c:6: warning: data definition has no type or storage class
tut_intcopy.c:6: error: conflicting types for ‘pointerA’
tut_intcopy.c:5: error: previous declaration of ‘pointerA’ was here
tut_intcopy.c:6: warning: initialization makes integer from pointer without a cast

full code:
#include <stdlib.h>
#include <stdio.h>
int intsA[5] = {9,9,9,9,9};
int intsB[5] = {0,0,0,0,0};
int *pointerA, *pointerB;
pointerA = intsA;

int nbr;

void int_copy(int *ptriA, int *ptriB, int nbr)
{
   while (nbr != 0)
   {
      *pointerB++ = *pointerA++;
      nbr--;
   }
   *pointerB = '\0';
   return (0);
}   

int main()
{
    nbr = 3;	
    int_copy(pointerB, pointerA, nbr);
    for(int i=0;i<(sizeof(intsB)); i++);
       printf("%d ",intsB[i]));
}    

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial