pointer and array arithmetic

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Mar 2006
Posts: 4
Reputation: yaya is an unknown quantity at this point 
Solved Threads: 0
yaya yaya is offline Offline
Newbie Poster

pointer and array arithmetic

 
0
  #1
Mar 23rd, 2006
question about pointer and array.
can we add a 2-D array (**A) with a 1-D array (*B)? both of the array is define as a pointer in the program.
where array A is A[i][j] and B is B[i]

new in C programming and pointer is difficult.... :-|
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,052
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: pointer and array arithmetic

 
2
  #2
Mar 23rd, 2006
Um... yes. But not with the + operator, of course; with some specially built procedure. I don't know what you mean by 'add', either, but surely there's some way for you to write the algorithm.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 4
Reputation: yaya is an unknown quantity at this point 
Solved Threads: 0
yaya yaya is offline Offline
Newbie Poster

Re: pointer and array arithmetic

 
0
  #3
Mar 23rd, 2006
the solution i need to obtain is
sum[i] = A[i][j] + B[i];

couldn't add 2-d array and 1-d array using + or using IMSL libraries. is it cause of A is a 2-D array? is that mean that sum[i] and B[i] have to be 2-D array?

i'm try to use this method (something similiar), where *B will become **B,

void pointTo(char **src, char *dst);
int main() {
/* local variables */
char text[3];
char *ptr;
/* point our pointer to our local variable */
pointTo(&ptr, text);
/* modify pointer data; affects local data due to pointer linkage */
ptr[0] = 'A';
ptr[1] = '\0';
/* end program */
return 0;
}
void pointTo(char **src, char *dst) {
*src = dst;
}
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,829
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 750
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: pointer and array arithmetic

 
0
  #4
Mar 23rd, 2006
>the solution i need to obtain is
>sum[i] = A[i][j] + B[i];
What are the types of A, B, and sum? I really don't see what the problem is unless A[i][j] and B[i] are incompatible for addition, or sum[i] can't hold a value of the result.
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 4
Reputation: yaya is an unknown quantity at this point 
Solved Threads: 0
yaya yaya is offline Offline
Newbie Poster

Re: pointer and array arithmetic

 
0
  #5
Mar 23rd, 2006
Originally Posted by Narue
>the solution i need to obtain is
>sum[i] = A[i][j] + B[i];
What are the types of A, B, and sum? I really don't see what the problem is unless A[i][j] and B[i] are incompatible for addition, or sum[i] can't hold a value of the result.
the actual function i'm trying to get is

for (j=0; j < N_tm[1]; j++){
for (i=0; i < N_sp[1]; i++)
{
*P = *R + gm[i][j];
*P++;
}
}

previously instead of gm[][], i had used **gm. but this still doesn't work.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,829
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 750
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: pointer and array arithmetic

 
0
  #6
Mar 23rd, 2006
>the actual function i'm trying to get is
That's not helpful and you're not listening to my question. Post the declarations of the relevant variables.
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 4
Reputation: yaya is an unknown quantity at this point 
Solved Threads: 0
yaya yaya is offline Offline
Newbie Poster

Re: pointer and array arithmetic

 
0
  #7
Mar 23rd, 2006
all variables are float.

the solution couldn't be calculate using pointer like that one i post previously.

solution should be used is
P[i] = R[i] + gm[i][j]

this is only working with array, not pointer.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,829
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 750
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: pointer and array arithmetic

 
0
  #8
Mar 23rd, 2006
Originally Posted by yaya
all variables are float.

the solution couldn't be calculate using pointer like that one i post previously.

solution should be used is
P[i] = R[i] + gm[i][j]

this is only working with array, not pointer.
Maybe someone else is interested in divining your problem from the babble you've given us, but I'm not. Perhaps when you can mange to describe your problem in a useful way and give us enough informatin to help you, I'll lend my assistence.
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC