Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*lsp getc() 함수 예제 172p*/
- /*ssu_getc.c*/
- /*20162468 박다은*/
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/time.h> //gettimeofday
- int main()
- {
- struct timeval A, B, C; //시간을 비교할 값들
- gettimeofday(&A, NULL);
- //=======================================
- int character;
- while((character = getc(stdin)) != EOF) //EOF가 들어올떄까지 계속 입력받음
- if(putc(character, stdout) == EOF){
- fprintf(stderr, "standard output error\n");
- exit(1);
- }
- if(ferror(stdin)){
- fprintf(stderr, "standard input error\n");
- exit(1);
- }
- //=======================================
- gettimeofday(&B, NULL);
- C.tv_sec = B.tv_sec - A.tv_sec;
- C.tv_usec = B.tv_usec - A.tv_usec;
- if(C.tv_usec < 0){
- C.tv_sec -= 1;
- C.tv_usec += 1000000;
- }
- printf("ROLLCAKE::Running Time : %ld µs\n", C.tv_sec*1000000 + C.tv_usec); //작은 프로그램이므로 마이크로초로 계산
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement