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.
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.
#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;
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.
That code builds just fine for me... the error must be related to something else.
Can you post the actual code please?
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:
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]));
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.