On Wed, 2006-10-25 at 00:46 -0700, jobo wrote:
Hello,
I'm trying to detect the EOF for scanf. But for some reason I can't get
it to trigger. What am I doing wrong? Thanks.
First off, excellent job formatting. One minor issue: you shouldn't
use // comments on Usenent because they'll eventually wrap over and
become syntax errors. I've changed your code in that respect.
int puzzle[9][9]; /* Puzzle data structure */
Hey, hey hey! Where did you start main()? You need to post
a /compilable/ snippit.
int i, j, count; /* Iteration variables */
int temparr[81];
Magic numbers make me nervous. (At the very least, comment in that it's
an array as large as puzzle[][]).
char x;
int test;
count = 0;
while (count < 82){
There's that magic number again! Use <= 81 to be consistent, but you
should really define some constants at the start of your program.
>
scanf("%c", &x);
Just use getchar() for this:
x = getchar();
Much simpler, no?
if (x == EOF) {
Here's your problem: EOF is not necessarily in the range of char.
(Specifically, if char is unsigned, it is not, but if char is signed
[which is likely], it may be.) Define x as int so that you are
guaranteed to be able to hold EOF.
printf("FUCK!");
Having a little trouble with this one, eh? ;-)
printf("%d", count);
return 0;
}
test = x;
if (test >= 48 && test <= 57) {
What is this test? It looks like some character test dependant on ASCII.
#include <ctype.hand use isalpha(), isdigit() and friends instead.
test = test - 48;
Ditto here. I think that you're trying to convert a character digit to a
numberic one. In that case, try
test -= '0';
Your intent will be much clearer.
temparr[count]= test;
count++;
}
}
Where were you using the puzzle[][] array? Or i and j? You should have
just gotten rid of them if they were unnecessary to your post.
--
Andrew Poelstra <http://www.wpsoftware.net/projects/>