PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Using getch and putch...

I am having problems with getch() and putch(), and I would like to know how to properly use it. I tried doing this:

Code:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

main()
{

char a[5];

printf("Is your printer on? y/n: ");
getchar(a);
if (a == 'n')
{
printf("I'll wait. Press Enter when you have it on...\n");
getchar(a);
}
system("PAUSE");
return 0;
}


I recieved multiple errors and warnings. Please explain on how to properly use getch() and putch(), my C book is not very good...
getchar returns a char, it does not accept a char array as an argument.

Code:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

main()
{

char a;

printf("Is your printer on? y/n: ");
a=getchar();
if (a == 'n')
{
printf("I'll wait. Press Enter when you have it on...\n");
a=getchar();
}
system("PAUSE");
return 0;
}
Dan East wrote:
getchar returns a char, it does not accept a char array as an argument.


And a warm welcome goes out to Greg Perry, ladies and gentleman...

Greg Perry, the author of my C book, clearly makes a lot of mistakes. This is also the 2nd edition of the book! It's madness I tell you!

By the way, thank you very much for explaining about getch().
getchar() - waits for a carriage return.

getch() - proceeds after you press a key.

Reminds me of 'Hello World' stuff back in my college days... Cheers :-)
You're better off doing this:
[code][/code]
Dave Johnston · 15 Jul 2003, 20:54 UTC
max wrote:
You're better off doing this:
[code][/code]


Is that optimised?
You guys are wearing HIGH TECH MAGNIFYING GLASS?

I can't read the codes he posted, so I cant tell if that's optimized :-)
Whoa, I just noticed... I'm browsing in Galeon/Mozilla and the code box actually WORKS!

Thanks, Dan :D