Notice
                              
                          
                        
                          
                          
                            Recent Posts
                            
                        
                          
                          
                            Recent Comments
                            
                        
                          
                          
                            Link
                            
                        
                    | 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 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 | 
                            Tags
                            
                        
                          
                          - bitcoin
 - write
 - Sync
 - json
 - http
 - Close
 - Callback
 - Golang
 - C
 - Python
 - File
 - channel
 - 책
 - tcp
 - go언어
 - 영화
 - mutex
 - 리뷰
 - range
 - API
 - GO 언어
 - install
 - FOR
 - windows
 - window
 - Linux
 - go
 - package
 - JavaScript
 - c++
 
                            Archives
                            
                        
                          
                          - Today
 
- Total
 
목록ftell (1)
Code Habit
      
      
        c/c++ 파일 크기만큼 파일 읽기
        
  
  
        
    
            
            
            
            
            
            
              
            
          c언어 함수인 fopen을 이용해 파일을 열고 파일의 크기를 먼저 구한 후 크기만큼 파일을 읽는 예제이다. 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 int main(void) { char* buffer; int size; int count; FILE *fp = fopen("test.txt", "r"); if (NULL == fp) { return -1; } fseek(fp, 0, SEEK_END); // 파일 포인터를 파일의 끝으로 이동시킴 size = ftell(fp); // 파일 포인터의 현재 위치를 얻음 => 파일 사이즈 buffer = new char[size+1]; // 파일 크기 + 1바이트(문자열 마지막의 NULL)..
        카테고리 없음
        
        2020. 9. 27. 17:55