|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
gets() and getchar() |
Posted: Mon Nov 08, 2004 9:19 am |
|
|
I could use getchar() get individual ASCII data from RS232, but I could not use gets() function. what is the matter, I used this for testing
send 'RB' from rs232
used
char b; b1[30];
b=getchar()
if(b=='R')
output_high(PIN_a2);
and
gets(b1);
b=b1[0];
if(b=='R')
output_high(PIN_a2);
first code works, second didi not? |
|
|
Ttelmah Guest
|
Re: gets() and getchar() |
Posted: Mon Nov 08, 2004 9:29 am |
|
|
Anonymous wrote: | I could use getchar() get individual ASCII data from RS232, but I could not use gets() function. what is the matter, I used this for testing
send 'RB' from rs232
used
char b; b1[30];
b=getchar()
if(b=='R')
output_high(PIN_a2);
and
gets(b1);
b=b1[0];
if(b=='R')
output_high(PIN_a2);
first code works, second didi not? |
Gets, requires a line feed to terminate the string. Hence you would have to send 'RB', and then an <enter>, before the gets version will work.
Best Wishes |
|
|
Guest
|
|
Posted: Mon Nov 08, 2004 9:42 am |
|
|
Thank you Ttelmah, according to your suggestion, if I want to send several strings, like,
char a[10], b[10], c[10] from RS232
then
after send the a[10], I have to send a '\r' right? '\r\' is a return right?
and then afetr b[10] a '\r' afer c[10] a'\r' and then
I could use gets() like
char a1[10], b1[10],c1[10];
gets(a1);
gets(b1);
gets(c1);
to get the transfered data rght?
thank you. |
|
|
Guest
|
|
Posted: Mon Nov 08, 2004 9:49 am |
|
|
what I meaning in the last one is for multiple strings receives. |
|
|
krakatau
Joined: 19 Feb 2009 Posts: 9
|
|
Posted: Wed Apr 01, 2009 2:38 am |
|
|
THANKS A LOT GUYS. i was required it.
thanksssssss
maybe thanks sent very years later. |
|
|
|
|
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
|