Page 2 of 2

Posted: Mon Oct 01, 2007 5:32 am
by JamesM
If you're programming this in your own OS (A lot of the replies earlier assumed this was in a hosted environment), then you should DEFINATELY use static allocation with a max size, thus:

Code: Select all

 
unsigned int gets(char *buffer, unsigned int max_length) 
{ 
  unsigned int sz = 0; 
  while( (*buffer++=getc()) != '\n' && 
         sz < max_length-1) 
    sz++; 
  *--buffer  = '\0'; 
  return sz; 
} 

... in main.c ... 

char string[512];
gets(string, 512); 
JamesM

Posted: Mon Oct 01, 2007 11:04 pm
by mohammed
it worked fine thank you but i am going to attach it to the IRQ when the user hit a key the handler search for what function is in use
because i still have problem with this
while (! (inportb(0x64) & 0x1) ) ;
my speed on the keyboard affect what appears on the screen

Posted: Tue Oct 02, 2007 5:01 am
by Candy
JamesM wrote:If you're programming this in your own OS (A lot of the replies earlier assumed this was in a hosted environment), then you should DEFINATELY use static allocation with a max size
Where did you get that logic from? If you have dynamic allocation, use it. If you do not, then use static allocation.

Posted: Tue Oct 02, 2007 6:04 am
by JamesM
But he doesn't have dynamic allocation in his OS yet, and he seems to get confused easily...