17.02.2015 Views

CCS C Compiler Manual PCB / PCM / PCH

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Built-in Functions<br />

Examples:<br />

printf("Continue (Y,N)?");<br />

do {<br />

answer=getch();<br />

}while(answer!='Y' && answer!='N');<br />

#use rs232(baud=9600,xmit=pin_c6,<br />

rcv=pin_c7,stream=HOSTPC)<br />

#use rs232(baud=1200,xmit=pin_b1,<br />

rcv=pin_b0,stream=GPS)<br />

#use rs232(baud=9600,xmit=pin_b3,<br />

stream=DEBUG)<br />

...<br />

while(TRUE) {<br />

c=fgetc(GPS);<br />

fputc(c,HOSTPC);<br />

if(c==13)<br />

fprintf(DEBUG,"Got a CR\r\n");<br />

}<br />

Example<br />

Files:<br />

Also See:<br />

ex_stwt.c<br />

putc(), kbhit(), printf(), #USE RS232, input.c, RS232 I/O Overview<br />

gets( ) fgets( )<br />

Syntax:<br />

Parameters:<br />

Returns:<br />

Function:<br />

gets (string)<br />

value = fgets (string, stream)<br />

string is a pointer to an array of characters.<br />

Stream is a stream identifier (a constant byte)<br />

undefined<br />

Reads characters (using getc()) into the string until a RETURN (value 13) is<br />

encountered. The string is terminated with a 0. Note that INPUT.C has a more<br />

versatile get_string function.<br />

If fgets() is used then the specified stream is used where gets() defaults to<br />

STDIN (the last USE RS232).<br />

Availability:<br />

Requires:<br />

Examples:<br />

All devices<br />

#USE RS232<br />

char string[30];<br />

printf("Password: ");<br />

gets(string);<br />

if(strcmp(string, password))<br />

printf("OK");<br />

179

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!