PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Nov 16, 2003 6:01 pm |
|
|
Quote: | OK I see from this that it takes the following form:
void get_string(char * s,int max)
Does this mean that 'max' defines the maximum number of characters that can be accepted by this function? What does 'len' do? |
'max' is actually the buffer size. The number of chars you
can enter is 1 less than this amount. ie, in the following
program, you can enter up to 3 chars. The last buffer element
is reserved for the string terminator char of 0, which is
inserted by get_string().
'len' is an internal variable used by the function to keep
track of how many chars you have entered. You don't
have to deal with 'len', because it's not part of the parameter
list. You only have to specify the buffer pointer, and the
buffer size.
Code: | #include <16F877.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 8000000)
#use rs232(baud = 9600, xmit=PIN_C6, rcv = PIN_C7, ERRORS)
#include <input.c>
#define BUF_SIZE 4
main()
{
char array[BUF_SIZE];
// Type in a string, and then press the Enter key.
get_string(array, BUF_SIZE);
printf("\n\r%s", array); // Display the string.
while(1);
} |
|
|