Function array and pointer
I can only get the first element of an array to work when passed to another function.
If i try to print out the next element of that array in that function i dont get the result i expected (the strings has 1 letter fewer from the begining when i write e.g: array+i).
Can someone please tell me what i have done wrong or what is missing?
The problem is apparent when you see the result of the printf() function, which is in the function roa() and that's where the problem lies i suspect.
Code:
/*Pointer array test.*/
#include <stdio.h>
void blank(void);
void roa(char *a,char *b,int *c);
int main(void){
int i;
int age[3] = {20,21,18};
char first[12] = "Tree";
char first1[12] = "Water";
char first2[12] = "Dirt";
char last[12] = "Strotter";
char last1[12] = "Bridge";
char last2[12] = "Stone";
char *given[3];
char *family[3];
*given = first;
*(given+1) = first1;
*(given+2) = first2;
*family = last;
*(family+1) = last1;
*(family+2) = last2;
blank();
printf("Name Lastname Age\n");
for(i=0;i<3;i++)printf("%s %s %d\n",*(given+i),*(family+i),*(age+i));
roa(*given,*family,age);
return 0;}
void blank(void){
int i;
for(i=0;i<80;i++)printf("#");
for(i=0;i<80;i++)printf("#");
for(i=0;i<32;i++)printf(" ");printf("Array Pointer Test\n");
for(i=0;i<80;i++)printf("#");
for(i=0;i<9;i++)printf("\n");}
void roa(char *a,char *b,int *c){
int i;
printf("\nroa()\nName Lastname Age\n");
for(i=0;i<3;i++)printf("%s %s %d\n",a+i,b+i,*(c+i));}