Hacker News new | ask | show | jobs
by Someone 602 days ago
I suggest you write a few test cases to verify that it works reliably. I have my doubts about that, given this code fragment:

    // stop hashing when there is nothing left to hash
    while (scanf("%d", &ch) != EOF) {
        // get the current byte
        ch = getchar();
2 comments

I replaced that code with

  // loop until an EOF is read
  while ((ch = getchar()), ch != EOF) {
Would this be better?
How would you suggest I replace that? I am a C novice but I have heard of the buffer overflows caused by scanf.