CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

knotty problem with string functions

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 16, 2003 6:01 pm     Reply with quote

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);

}
adrian



Joined: 08 Sep 2003
Posts: 92
Location: Glasgow, UK

View user's profile Send private message

PostPosted: Tue Nov 18, 2003 2:15 am     Reply with quote

Many thanks for your help guys - I now have working code.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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