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 CCS Technical Support

problem with pointer to an array
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 22, 2006 10:28 pm     Reply with quote

I was able to make it work by revising the InitBuf routine. Apparently
the CCS compiler can't properly parse the syntax in your example.
I tested two alternate methods and they both worked. I used PCM
vs. 3.249 to compile the code. This was the output:
Quote:

First Values: A A A A A A A A A A
Second Values: B B B B B B B B B B


In this one I used an intermediate pointer:
Code:

void InitBuf (char **Buf, int length, char Value)
{
int i;
char *ptr;

ptr = *Buf;

for(i = 0; i < length; i++)
    ptr[i] = Value;
}


In this one I avoided using the array syntax:
Code:

void InitBuf (char **Buf, int length, char Value)
{
int i;

for(i = 0; i < length; i++)
    *(*Buf +i) = Value;
}



Complete test program:
Code:

#include <16F877.h>
#fuses HS, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#include <stdlibm.h>

//------------------------------------------
void InitBuf (char **Buf, int length, char Value)
{
int i;
char *ptr;

ptr = *Buf;

for(i = 0; i < length; i++)
    ptr[i] = Value;
}

/*
//-----------------------------------------
void InitBuf (char **Buf, int length, char Value)
{
int i;

for(i = 0; i < length; i++)
    *(*Buf +i) = Value;
}
*/

//=======================================
int main ()
{
char *Buf;
int i;

Buf = (char *) malloc (sizeof (char) * 10);

InitBuf(&Buf, 10, 'A');

printf ("First Values: ");

for(i = 0; i < 10; i++)
    printf ("%c ", Buf[i]);


InitBuf(&Buf, 10, 'B');

printf ("\nSecond Values: ");

for(i = 0; i < 10; i++)
    printf ("%c ", Buf[i]);

while(1);
}
andreluizeng



Joined: 04 Apr 2006
Posts: 117
Location: Brasil

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Mon Oct 23, 2006 7:05 am     Reply with quote

PCM,

thanks a lot,

my compiler's version is 3.221, and i cant compile it...

when i use char **, i gave this error: Expetion ',' or ')'

this is my question.....

how can i compile it ?


regards
_________________
Andre
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 23, 2006 11:52 am     Reply with quote

I tested PCM vs. 3.221 and I agree that it doesn't like **Buf.

Possibly you can go the route given in this thread.
http://www.ccsinfo.com/forum/viewtopic.php?t=27813
andreluizeng



Joined: 04 Apr 2006
Posts: 117
Location: Brasil

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Tue Oct 24, 2006 11:25 am     Reply with quote

Alright PCM,

thanks a lot for the help.


regards.
_________________
Andre
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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