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

Functions, Math

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



Joined: 07 May 2005
Posts: 28
Location: Campbell, CA

View user's profile Send private message

Functions, Math
PostPosted: Sun May 22, 2005 12:56 pm     Reply with quote

I have taught myself enough to get some things working, but now I need functions. I'm trying to clear a keyboard buffer, and I have the following lines in my program

Clear_Keyboard_Buffer()
for (i=0;i<11;i++)
{Keyin_buffer[i] = 0;}
return;

I want to be able to issue the command "Clear_Keyboard_Buffer" and
have the program run off and do that.
Unfortunately, when I compile, I get the message "Undefined Identifier - Clear_Keyboard_Buffer".
What do I need to change in order to get this to do what I want?

Next question: I am accepting characters from the keyboard in an array, and I need to filter out certain characters, such as <CR> and <ESC>. In another (un-named) language, I would define my input as INT and would look for 0x0D, etc. When I wanted to display the characters, I would add 0x30 and display them. In C, is there a way to trap control characters such as <ENTER> and <ESC> using type 'char'? If not and I have to store the input as 'int', then how do I convert the type to 'char" in order to display what was typed?
Ttelmah
Guest







PostPosted: Sun May 22, 2005 2:32 pm     Reply with quote

Code:

Clear_Keyboard_Buffer()
{
   int i;
   for (i=0;i<11;i++)
      Keyin_buffer[i] = 0;
}

You do not need the brackets round the 'keyin_buffer[i]=0' statement, but you do need them round the body of code. Also any variabels used locally (I am assuming that 'keyin_buffer' is declared globally), ust be declared inside the function.
This declaration should either appear before you want to use the function, or you need a 'prototype' declaration before you use the function - just:
Clear_Keyboard_Buffer();
In the body of the code, outside any functions, before you want to use the command.

If 'i' is also global, then you could just use a macro definition instead, with:
Code:

#define Clear_Keyboard_Buffer()    for (i=0;i<11;i++) \
      Keyin_buffer[i] = 0

Here this 'block' of code will be subsituted into the compiled result. Note the '\' which stops the line feed from ending the statement, and the lack of a trailing ';', since the one typed after the command will still be here.
Again the definition must be before the operation is used.

Best Wishes
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