[ create a new paste ] login | about

Link: http://codepad.org/N8n7P5tF    [ raw code | output | fork ]

C, pasted on Oct 11:
#include <stdio.h>

#define CTRL_POS 100
#define CTRL_LETTER 'a'
#define CTRL_DIGIT '1'
#define DIGITS_FILE_NAME "digits.txt"
#define LETTERS_FILE_NAME "letters.txt"

int main(void){
  int letter, digit, i;
  FILE * fDigits, * fLetters;

  if ( ( fDigits = fopen(DIGITS_FILE_NAME, "r") ) == NULL ){
    fprintf(stderr, "Can't open file %s\n", DIGITS_FILE_NAME);
    return 1;
  }

  for ( i = 0; i < CTRL_POS; ++i ){
    if ( ( digit = fgetc(fDigits) ) == EOF ){
      fprintf(stderr, "Can't read from file %s\n", DIGITS_FILE_NAME);
      fclose(fDigits);
      return 1;
    }
  }

  fclose(fDigits);

  if ( ( fLetters = fopen(LETTERS_FILE_NAME, "r") ) == NULL ){
    fprintf(stderr, "Can't open file %s\n", LETTERS_FILE_NAME);
    return 1;
  }

  for ( i = 0; i < CTRL_POS; ++i ){
    if ( ( letter = fgetc(fLetters) ) == EOF ){
      fprintf(stderr, "Can't read from file %s\n", LETTERS_FILE_NAME);
      fclose(fLetters);
      return 1;
    }
  }

  fclose(fLetters);

  printf("%s\n", ( digit == CTRL_DIGIT && letter == CTRL_LETTER ) ? "Aga!" : "Nicht!");
  
  return 0;
}

  


Output:
1
Can't open file digits.txt


Create a new paste based on this one


Comments: