메뉴 건너뛰기

app

[c] line 수 세는 프로그램

박영식2009.08.14 00:35조회 수 3897댓글 0

    • 글자 크기
#include <fcntl.h>
#include <stdio.h>

long ch;
long word;
long line;

main(void)
{
FILE *ifp, *ofp;
char buffer[BUFSIZ];
int file, j, i;

ifp = fopen("input.txt", "r");
ofp = fopen("output.txt", "w");

if((file = open("input.txt", O_RDONLY)) < 0) {
perror("open error");
exit(1);
}
while( (j = read(file, buffer, BUFSIZ )) > 0 ) {
ch += j;
for(i=0 ; i < j ; i++) {
if( buffer[i]==' ' || buffer[i]=='n') {
word++;
if(buffer[i] == 'n')
line++;
}
}
}
fprintf(ofp, "글자수 : %ldn워드수 : %dn라인수 : %dn", ch, word, line);
fclose(ifp);
fclose(ofp);
}


이를 linux에서 gcc를 이용해 컴파일 할 수 있다.

# gcc -o line line.c
#./line
으로 실행할 수 있다.
박영식 (비회원)
    • 글자 크기
[rooting] Umidigi A5 pro Pie(Android 9) (by suritam9) [PHP] letter, word, line 수 세기 (by 박영식)

댓글 달기

이전 1 ... 5 6 7 8 9 10 11 12 13 14 다음
첨부 (0)
위로