---유틸리티 루틴---
문자열
복사 strcpy*, strncpy, strlncpy
연결 strcat*, strncat
비교 strcmp*, strncmp, strcasecmp, strncasecmp
탐색 strchr, strrchr, strstr
추출 strlen*, strpbrk, strtok, strtok_r, strspn, strcspn
---저수준 입출력 루틴---
파일열기와 닫기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#include <fcntl.h>
#include <stdio.h>
int main()
{
// char *fname="test.txt";
char *fname="/etc/passwd";
int fd;
fd=open(fname,O_RDONLY); //test.txt 파일이 미리 존재해야 함
if(fd<0)
perror("open()");
else{
printf("Success!\nFilename:%10s\nDescriptor:%d\n",fname,fd);
close(fd);
}
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs |
입력
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
32
33
34
35
|
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
// char *fname="test.txt";
char *fname="/etc/passwd";
int fd;
int linecnt=0;
char c;
if((fd=open(fname,O_RDONLY))<0) {
perror("open()");
exit(-1);
}
for( ; ;) {
if(read(fd,&c,1)>0) {
if(c=='\n') linecnt ++;
} else break;
}
printf("Total line : %d\n",linecnt);
/*
fd=open(fname,O_RDONLY);
if(fd<0)
perror("open()");
else{
printf("Success!\nFilename:%10s\nDescriptor:%d\n",fname,fd);
close(fd);
}
*/
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs |
'딥러닝 기반 영상인식 개발 전문가 과정 > 리눅스' 카테고리의 다른 글
5월29일 리눅스 2 형기반입출력, 줄단위, 버퍼기반, 읽기/쓰기 오프셋 재배치, 디렉토리 생성과 삭제 (0) | 2019.05.29 |
---|---|
5월29일 리눅스 1 #dup삭제#Seeker삭제#디스크립터삭제#오프셋삭제#FILE삭제#스트림삭제# (0) | 2019.05.29 |
5월 27일 VIM (0) | 2019.05.27 |
5월25일 리눅스 실습들 (0) | 2019.05.25 |
5월23일 함수 포인터 문제 (0) | 2019.05.23 |