We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,111 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Passing pointer to 3D array and then using pointer arithmetic

I am trying to pass a pointer to a 3D array to a function in which I want to access an array element using pointer arithmetic.

Define the array:

const unsigned char TS_list_string[2][2][3] = 
{       
 "abc",   "def", 
 "ghi",   "jkl",  
};

Define the function

void process_ts(const unsigned char *T1)
{
unsigned char dv;

    dv = *(*(*(T1 + 1) + 1) + 2);  <----- Compiler error: "Operand of * must be a pointer
}

Main

int main()      
{                                
const unsigned char  *T1;

   T1 =  &TS_list_string[0][0][0];

   process_ts( T1);
}    

Does anyone know what I am doing wrong?

2
Contributors
2
Replies
56 Minutes
Discussion Span
9 Months Ago
Last Updated
3
Views
c_program_user
Newbie Poster
4 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Does anyone know what I am doing wrong?

Mainly, if it's supposed to be a string, where's the space for the \0 that terminates a string?

WaltP
Posting Sage w/ dash of thyme
Team Colleague
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 37

Yes, the last dimension should be 4 rather than 3 to store the terminator. But that is not the problem, which you do not address.

c_program_user
Newbie Poster
4 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0777 seconds using 2.65MB