944,106 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 3194
  • C RSS
Mar 23rd, 2006
0

pointer and array arithmetic

Expand Post »
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.... :-|
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
yaya is offline Offline
4 posts
since Mar 2006
Mar 23rd, 2006
2

Re: pointer and array arithmetic

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.
Team Colleague
Reputation Points: 1135
Solved Threads: 172
Super Senior Demiposter
Rashakil Fol is offline Offline
2,479 posts
since Jun 2005
Mar 23rd, 2006
0

Re: pointer and array arithmetic

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;
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
yaya is offline Offline
4 posts
since Mar 2006
Mar 23rd, 2006
0

Re: pointer and array arithmetic

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Mar 23rd, 2006
0

Re: pointer and array arithmetic

Quote 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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
yaya is offline Offline
4 posts
since Mar 2006
Mar 23rd, 2006
0

Re: pointer and array arithmetic

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Mar 23rd, 2006
0

Re: pointer and array arithmetic

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
yaya is offline Offline
4 posts
since Mar 2006
Mar 23rd, 2006
0

Re: pointer and array arithmetic

Quote 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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Nov 12th, 2010
0
Re: pointer and array arithmetic
plz help to write a c program to add to matrix using pointer.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
somnath Basak is offline Offline
1 posts
since Nov 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Counting vowels and consonants
Next Thread in C Forum Timeline: C/C++ Compiler for Windows





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC