tôi nhận được một lỗi segmentation với mã này trên fprintf:lỗi segmentation trên thiết bị đầu cuối giả
#define _GNU_SOURCE
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdint.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
int fd;
int main(int argc, char **argv) {
fd = posix_openpt(O_RDWR | O_NOCTTY);
fprintf(fd, "hello\n");
close(fd);
}
Nhưng nó hoạt động tốt với:
fprintf(stderr, "hello\n");
gì đang gây ra điều này?
Bạn đã kiểm tra kết quả của posix_openpt() chưa? – Greycon
fprintf() yêu cầu một TẬP_TIN * không phải là một bộ mô tả tập tin – Carles
Bạn không nên bỏ qua các cảnh báo mà bạn không hiểu ... Đặc biệt nếu dòng tương ứng gây ra sự phân đoạn. – mafso