 |
 |
| View previous topic :: View next topic |
| Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Oct 22, 2006 10:28 pm |
|
|
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
|
|
Posted: Mon Oct 23, 2006 7:05 am |
|
|
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
|
|
 |
andreluizeng
Joined: 04 Apr 2006 Posts: 117 Location: Brasil
|
|
Posted: Tue Oct 24, 2006 11:25 am |
|
|
Alright PCM,
thanks a lot for the help.
regards. _________________ Andre |
|
 |
|
|
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
|