質問編集履歴
1
フォームの訂正
    
        title	
    CHANGED
    
    | 
         
            File without changes
         
     | 
    
        body	
    CHANGED
    
    | 
         @@ -8,14 +8,18 @@ 
     | 
|
| 
       8 
8 
     | 
    
         
             
            (改行)
         
     | 
| 
       9 
9 
     | 
    
         
             
            (改行)
         
     | 
| 
       10 
10 
     | 
    
         
             
            (改行)
         
     | 
| 
      
 11 
     | 
    
         
            +
            欲しい実行結果:
         
     | 
| 
      
 12 
     | 
    
         
            +
            abc
         
     | 
| 
      
 13 
     | 
    
         
            +
            efg
         
     | 
| 
      
 14 
     | 
    
         
            +
            hij
         
     | 
| 
       11 
15 
     | 
    
         
             
            ###該当のソースコード
         
     | 
| 
       12 
     | 
    
         
            -
            C言語で記述
         
     | 
| 
       13 
     | 
    
         
            -
            # 
     | 
| 
      
 16 
     | 
    
         
            +
            ###read_file.c
         
     | 
| 
      
 17 
     | 
    
         
            +
            ```c
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
      
 18 
     | 
    
         
            +
            #include <stdio.h>
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 19 
     | 
    
         
            +
            #include <stdlib.h>
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
            #include <string.h>
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
      
 21 
     | 
    
         
            +
            #include <assert.h>
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
      
 22 
     | 
    
         
            +
            #define ALLOC_SIZE (256)
         
     | 
| 
       19 
23 
     | 
    
         | 
| 
       20 
24 
     | 
    
         
             
            static char *st_line_buffer = NULL;
         
     | 
| 
       21 
25 
     | 
    
         | 
| 
         @@ -74,29 +78,30 @@ 
     | 
|
| 
       74 
78 
     | 
    
         
             
            	st_current_buffer_size = 0;
         
     | 
| 
       75 
79 
     | 
    
         
             
            	st_current_used_size = 0;
         
     | 
| 
       76 
80 
     | 
    
         
             
            }
         
     | 
| 
      
 81 
     | 
    
         
            +
            ```
         
     | 
| 
      
 82 
     | 
    
         
            +
            ###read_line.h
         
     | 
| 
      
 83 
     | 
    
         
            +
            ```C 
         
     | 
| 
      
 84 
     | 
    
         
            +
            #ifndef READ_LINE_H_INCLUDED
         
     | 
| 
      
 85 
     | 
    
         
            +
            #define READ_LINE_H_INCLUDED
         
     | 
| 
       77 
86 
     | 
    
         | 
| 
       78 
     | 
    
         
            -
            #read_line.h
         
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
      
 87 
     | 
    
         
            +
            #include <stdio.h>
         
     | 
| 
       80 
     | 
    
         
            -
             #define READ_LINE_H_INCLUDED
         
     | 
| 
       81 
88 
     | 
    
         | 
| 
       82 
     | 
    
         
            -
             #include <stdio.h>
         
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
89 
     | 
    
         
             
             char *read_line(FILE *fp);
         
     | 
| 
       85 
90 
     | 
    
         
             
             void free_buffer(void);
         
     | 
| 
       86 
91 
     | 
    
         | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
      
 92 
     | 
    
         
            +
            #endif /* READ_LINE_H_INCLUDED */
         
     | 
| 
      
 93 
     | 
    
         
            +
            ```
         
     | 
| 
      
 94 
     | 
    
         
            +
            ###read_file.c
         
     | 
| 
      
 95 
     | 
    
         
            +
            ```C 
         
     | 
| 
      
 96 
     | 
    
         
            +
            #include<stdio.h>
         
     | 
| 
      
 97 
     | 
    
         
            +
            #include<stdlib.h>
         
     | 
| 
      
 98 
     | 
    
         
            +
            #include<assert.h>
         
     | 
| 
       88 
99 
     | 
    
         | 
| 
       89 
     | 
    
         
            -
            #read_file.c
         
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
      
 100 
     | 
    
         
            +
            #define ALLOC_SIZE  (256)
         
     | 
| 
       91 
     | 
    
         
            -
             #include<stdlib.h>
         
     | 
| 
       92 
     | 
    
         
            -
             #include<assert.h>
         
     | 
| 
       93 
101 
     | 
    
         | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
      
 102 
     | 
    
         
            +
            #include "read_line.h"
         
     | 
| 
       95 
103 
     | 
    
         | 
| 
       96 
     | 
    
         
            -
             #include "read_line.h"
         
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
            //このフォーム内では* *と書いてますが、実際はスペースを除いて書いてます
         
     | 
| 
       99 
     | 
    
         
            -
            char * 
     | 
| 
      
 104 
     | 
    
         
            +
            char **add_line(char **text_data, char *line, int *line_alloc_num, int *line_num)
         
     | 
| 
       100 
105 
     | 
    
         
             
            {
         
     | 
| 
       101 
106 
     | 
    
         
             
            	assert(*line_alloc_num >= *line_num );
         
     | 
| 
       102 
107 
     | 
    
         
             
            	if(*line_alloc_num == *line_num ){
         
     | 
| 
         @@ -109,8 +114,7 @@ 
     | 
|
| 
       109 
114 
     | 
    
         
             
            	return text_data;
         
     | 
| 
       110 
115 
     | 
    
         
             
            }
         
     | 
| 
       111 
116 
     | 
    
         | 
| 
       112 
     | 
    
         
            -
            //このフォーム内では* *と書いてますが、実際はスペースを除いて書いてます
         
     | 
| 
       113 
     | 
    
         
            -
            char * 
     | 
| 
      
 117 
     | 
    
         
            +
            char **read_file(FILE *fp, int *line_num_p)
         
     | 
| 
       114 
118 
     | 
    
         
             
            {
         
     | 
| 
       115 
119 
     | 
    
         
             
            	char **text_data = NULL;
         
     | 
| 
       116 
120 
     | 
    
         
             
            	int  line_num = 0;
         
     | 
| 
         @@ -140,7 +144,7 @@ 
     | 
|
| 
       140 
144 
     | 
    
         
             
            	}
         
     | 
| 
       141 
145 
     | 
    
         
             
            	return 0;
         
     | 
| 
       142 
146 
     | 
    
         
             
            }
         
     | 
| 
       143 
     | 
    
         
            -
             
     | 
| 
      
 147 
     | 
    
         
            +
            ```
         
     | 
| 
       144 
148 
     | 
    
         
             
            ###試したこと
         
     | 
| 
       145 
149 
     | 
    
         
             
            ソースをじっくりと見直し、調べたが分からなかった
         
     | 
| 
       146 
150 
     | 
    
         |