티스토리 뷰

책 ) 뇌를 자극하는 TCP/IP 소켓 프로그래밍

5장 파일과 소켓에 나오는 예제를 Window 식으로 바꿔보았습니다.

내용 자체는 간단해서 다른 설명을 추가하지는 않겠습니다.

#pragma warning(disable:4996)
#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>
//#include<errno.h>

#define MAXLINE 512

int main() {
	FILE* source_fd;
	FILE* dest_fd;
	int readn;
	int totaln = 0;
	char buf[MAXLINE];

	if (!(source_fd = fopen("test.txt", "r"))) {
		perror("Error : ");
		return 1;
	}
	if (!(dest_fd = fopen("copy.txt", "w+"))) {
		perror("Error : ");
		return 1;
	}
	memset(buf, 0x00, MAXLINE);
	fread(buf, 1, MAXLINE, source_fd);
	printf("%s\n", buf);

	fputs(buf, dest_fd);

	fclose(source_fd);
	fclose(dest_fd);
}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함