Неверный дескриптор файла

Я изучаю файловые дескрипторы и написал этот код:

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>

int fdrd, fdwr, fdwt;
char c;

main (int argc, char *argv[]) {

    if((fdwt = open("output", O_CREAT, 0777)) == -1) {
        perror("Error opening the file:");
        exit(1);
    }

    char c = 'x';

    if(write(fdwt, &c, 1) == -1) {
        perror("Error writing the file:");
    }

    close(fdwt);
    exit(0);

}

, но получаю: Ошибка записи файла :: Плохой дескриптор файла

Я не знаю, что может быть не так, поскольку это очень простой пример.

19
задан Sheena 16 March 2014 в 15:05
поделиться