전에 리눅스 질문올렸던 사람입니다
글쓴이: wkfdlek / 작성시간: 금, 2018/10/19 - 4:18오후
답변이 안되길래 다시 달면
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include "student.h"
#define START_ID 1201001
/* 학생 정보를 입력받아 데이터베이스 파일에 저장한다. */
int main(int argc, char *argv[])
{
int fd;
struct student record;
if (argc < 2) {
fprintf(stderr, "사용법 : %s file\n", argv[0]);
exit(1);
}
if ((fd = open(argv[1],O_WRONLY |O_CREAT|O_EXCL, 0640))==-1) {
perror(argv[1]);
exit(2);
}
printf("%7s %6s %4s\n", "학번", "이름", "점수");
while (scanf("%d %s %d", &record.id, record.name, &record.score) == 3) {
lseek(fd, (record.id - START_ID) * sizeof(record), SEEK_SET);
write(fd, (char *) &record, sizeof(record) );
}
close(fd);
exit(0);
}이 코드인데
밑에 첨부한 이미지처럼 나옵니다(첫번째 올린거는 코드친거. vim으로 했어요)
저거 fd도 -1로 되는거 같던데 뭐가 오류인거죠?
File attachments:
| 첨부 | 파일 크기 |
|---|---|
| 105.5 KB | |
| 36.36 KB |
Forums:


사용법 : ./dbcreate file
사용법 : ./dbcreate file
왜 사용법을 써 놓으시곤 사용법대로 안 쓰시는 거죠?
이미 답변이 달려있네요..
네... 직접 해봤습니다.
student.h 는 뻔하게 struct student 일테고...
네. 이렇게 수정해서 해봤습니다.
앗... 아아
뒤에 파일써야하네요 ㅎ
댓글 달기