View previous topic :: View next topic |
Author |
Message |
saee Guest
|
getc array send only one character |
Posted: Mon Dec 03, 2007 6:29 am |
|
|
when use getc function to array , with using putc ,specific array index sholud be send to the pc
for example
from pc : send 12345 to pic 16f877a
pic: read array ,getc, then send it for example second data,2, w
how???
c[]=getc;//read 12345
putc(c[1]);//send only 2
but how ??
this is not true |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Mon Dec 03, 2007 8:41 am |
|
|
I don't really understand your question, but this may help.
getc() and putc() normally only handle one byte, or character at a time. An odd addition to standard C in CCS is that if you give putc() a multi-byte argument the compiler calls putc() once for each byte. This can not work with getc() as the compiler has no way to know how many bytes are out there.
Maybe you should use string functions instead of byte (character) functions? _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 03, 2007 2:11 pm |
|
|
Look at the get_string() function, to get a string. It's in this CCS file:
Quote: | c:\Program Files\picc\Drivers\Input.c |
Also look at the puts() function, to send a string. |
|
|
Storic
Joined: 03 Dec 2005 Posts: 182 Location: Australia SA
|
Re: getc array send only one character |
Posted: Mon Dec 03, 2007 2:32 pm |
|
|
saee wrote: |
c[]=getc;//read 12345
putc(c[1]);//send only 2
|
putc(c[0]);//will send 1
when I was first learning C, I got confused with the fact C uses '0' as a valid count.
Code: |
for(i=0; i<=4; i++)
putc(c[i]);
|
should give you 12345 c[0],c[1],c[2],c[3],c[4], _________________ What has been learnt if you make the same mistake? |
|
|
yesahycs
Joined: 31 Oct 2007 Posts: 5
|
dun use putc |
Posted: Wed Dec 05, 2007 3:47 am |
|
|
try printf instead of putc.
ex:
int i;
for(i=0; i<=4; i++)
printf("%d",c[i]); |
|
|
|