Page 2 of 2
Posted: Tue Sep 25, 2007 12:06 am
by os64dev
However, you've been such a pain in the backside in the last few days that I don't feel inclined to look at your problem
Hmm.. somebody got out of bed with the wrong foot.
but then again people who write
*string++; instead of
string++; for advancing the pointer only should learn a little more about the language they are writing in.
Nevertheless, try separating the functions:
Code: Select all
char getch() {
//- code for getting a single character:
//- the problem will be in this function.
}
void gets(char * line) {
char ch;
while((ch = getch()) != '\n') *line++ = ch;
}
Posted: Tue Sep 25, 2007 12:10 am
by pcmattman
os64dev wrote:but then again people who write *string++; instead of string++; for advancing the pointer only should learn a little more about the language they are writing in.
It's valid - the postfix '++' occurs after the dereferencing and the data is assigned.
At least, it works for me
Posted: Tue Sep 25, 2007 12:16 am
by os64dev
i didn't talk about your code
*string++ = scancode; is valid and is also how i would use it. i meant the code of mohammed who wrote
*string++; just to advance the string see
Code: Select all
gets(unsigned char *string)
{
int strcounter = 0;
while (1)
{
while (! (inportb(0x64) & 0x1) );
scancode = kbdus[inportb(0x60)];
if(scancode != '\n'&&)
{
putch(scancode);
*string=scancode;
*string++;
}
else
*string++;
*string = '\0';
return *string;
}
}
Posted: Tue Sep 25, 2007 4:58 pm
by pcmattman
os64dev wrote:i didn't talk about your code
*string++ = scancode; is valid and is also how i would use it.
Oops, sorry! Should've read that post a bit more carefully...
Posted: Wed Sep 26, 2007 9:49 pm
by mohammed
What do you think of this :
Code: Select all
char getc()
{
unsigned char c;
while (! (inportb(0x64) & 0x1) ) ;
c = inportb(0x60);
putch(kbdus[c]);
return c;
}
gets(unsigned char *string)
{
char ch;
while(ch=getc() != '\n')
{
*string++;
}
*string++ = '\0';
}
but it didn't want to stop accept key strikes ! when i press enter it started new line!
Posted: Wed Sep 26, 2007 11:25 pm
by pcmattman
when i press enter it started new line!
Read your code and figure it out for yourself. It's not a difficult problem to figure out.
Posted: Thu Sep 27, 2007 2:08 am
by JamesM
Dear Jeebus, where did you learn to code? I count two MAJOR flaws with that code:
1) The one that you mentioned. I'm not going to give it to you, work it out yourself.
2) look at this line:
- and try and work out why your string will contain nothing but a null-terminator when your function returns
I really think your C coding skills aren't up to scratch. Maybe you should try programming something simpler before an OS, because I for one will not help you with such trivial problems.