(20200630: execution or displayed error?)
j:1 we recgnised |end_line + (|
and lines[1] printed just end_line: we've already realised today.
1. we think the reason we put '\0' to the lines array.
2. however, we realised in 2nd printing-loop, we do not touch the lines array.
Leading us to the wrong saying is thier technics, we think.
---
main.cpp Tue Jun 30 19:36:44 2020 1 :#include2 : 3 :int filesize( FILE *fp ) ; 4 : 5 :int main () { 6 : FILE *fp; 7 : int i; 8 : char dummy[256]; 9 : char* filename = ".\\alphabet-001.txt"; 10 : char* filename_split = ".\\001-split-001.txt"; 11 : char spit_line[10]; 12 : char lines[10][10]; 13 : 14 : fp = fopen(filename_split, "rb"); 15 : int file_end = filesize ( fp ); 16 : 17 : 18 : int start = 0; 19 : int j = 0; 20 : // first, we are going to find "spit_line". 21 : // each block should be stored as block name eve like "001-block---001.txt". 22 : // and we care following orders. 23 : // 24 : for ( i =0; i<file_end; i++ ) { 25 : printf("loop start i: %d: \r\n", i); 26 : fread ( dummy, 1, 1, fp); 27 : dummy[1] = '\0'; 28 : // find line end. 29 : if ( dummy[0] == '\n' ) { 30 : if ( i > 1 ) lines[j][i-1] = '\0'; 31 : else lines[j][0] = '\0'; 32 : j++; 33 : start = i; 34 : } 35 : lines[j][i - start] = dummy[0]; 36 : lines[j][i + 1 - start ] = '\0'; 37 : printf("loop end i: %d: %s j:%d|%s|\r\n", i, dummy, j, lines[j]); 38 : } 39 : printf("split_line: %s\r\n", spit_line); 40 : fclose(fp); 41 : 42 : for ( i =0; i<10; i++ ) { 43 : printf("lines[%d]|%s|\r\n", i, lines[i]); 44 : } 45 : 46 : 47 : /*fp = fopen(filename, "rb"); 48 : file_end = filesize ( fp ); 49 : for ( i =0; i<file_end; i++ ) { 50 : fread ( dummy, 1, 1, fp); 51 : dummy[1] = '\0'; 52 : printf("%d: %s\r\n", i, dummy); 53 : } 54 : 55 : close(fp);*/ 56 : return 0; 57 :} 58 : 59 :int filesize( FILE *fp ) { 60 : 61 : fseek(fp, 0L, SEEK_END); 62 : int sz = ftell(fp); 63 : 64 : fseek(fp, 0L, SEEK_SET); 65 : 66 : return sz; 67 :} --- loop start i: 0: loop end i: 0: - j:0|-| loop start i: 1: loop end i: 1: - j:0|--| loop start i: 2: loop end i: 2: - j:0|---| loop start i: 3: |j:0|---nd i: 3: loop start i: 4: loop end i: 4: j:1| | loop start i: 5: loop end i: 5: ( j:1| (| loop start i: 6: j:1| end i: 6: | loop start i: 7: loop end i: 7: j:2| | loop start i: 8: loop end i: 8: ) j:2| )| loop start i: 9: j:2| end i: 9: | loop start i: 10: loop end i: 10: j:3| | split_line: lines[0]|---| lines[1]| | lines[2]| | lines[3]| | lines[4]|m| lines[5]|タ・w| lines[6]|m| lines[7]|| lines[8]|@| lines[9]|5m|