CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

array of pointers?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hmmpic



Joined: 09 Mar 2010
Posts: 314
Location: Denmark

View user's profile Send private message

array of pointers?
PostPosted: Sat May 04, 2013 7:01 am     Reply with quote

Hi

Can anyone explain why function point1 is not working in CCS.
It is tested in real hw.

Compiler: 4140 - I have 4141 but it is not installed.
PIC:18F26K22

In "Code::Blocks" both ex work nice.

Code:

void p1(char *p[]){//Not working Print only some of the array?
int i;

 for (i=1; i<7; i++){
  printf("*P[]:%u_%s\r\n",i,p[i]);
 }
}

void p2(char **p){//working Print it all
int i;

 for (i=1; i<7; i++){
  printf("**P:%u_%s\r\n",i,p[i]);
 }
}

void pmain(){
int i;
static char string[]={"1;2;3;4;5;6;7;8;9;0"};
char *Cmdptr[10];
char *p;

p=string;
Cmdptr[1]=strtok(p,";");
Cmdptr[2]=strtok(NULL,";");
Cmdptr[3]=strtok(NULL,";");
Cmdptr[4]=strtok(NULL,";");
Cmdptr[5]=strtok(NULL,";");
Cmdptr[6]=strtok(NULL,";");

 for (i=1; i<7; i++){
  printf("Cmdptr:%u_%s\r\n",i,Cmdptr[i]);
 }

p1(Cmdptr);
p2(Cmdptr);
}


Last edited by hmmpic on Sun May 05, 2013 2:14 am; edited 5 times in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat May 04, 2013 4:26 pm     Reply with quote

Post your PIC and your compiler version.
hmmpic



Joined: 09 Mar 2010
Posts: 314
Location: Denmark

View user's profile Send private message

PostPosted: Sun May 05, 2013 1:16 am     Reply with quote

Hi

Compiler: 4140
PIC:18F26K22

I have 4141 but it is not installed.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun May 05, 2013 1:44 am     Reply with quote

You should post meaningful code. How are the pointers initialized and what is exactly "not working"?

A NULL pointer can't work.
hmmpic



Joined: 09 Mar 2010
Posts: 314
Location: Denmark

View user's profile Send private message

PostPosted: Sun May 05, 2013 2:15 am     Reply with quote

First post is now updated with ex.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun May 05, 2013 12:23 pm     Reply with quote

This has been a problem for a long time. To make it work with the
array syntax, you have to remove "char *" and declare the function
parameter as an array of int16 values. (Pointers are 16 bits for 18F PICs).
Example:
Code:

void p1(int16 p[]) {
int i;

 for (i=1; i<7; i++){
  printf("*P[]:%u_%s\r\n",i,p[i]);
 }
}

This works in vs. 4.141, but I think in some earlier versions you might
also have to put in the array size. For example, in your case:
Code:

void p1(int16 p[10]) {
hmmpic



Joined: 09 Mar 2010
Posts: 314
Location: Denmark

View user's profile Send private message

PostPosted: Mon May 06, 2013 4:17 am     Reply with quote

Hi @PCM p..

Thanks for information.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group